6 kyu

Linear Color Gradient

37 of 80aland97
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    There should probably be a sample test with the colors not ordered by position, because currently it only happens in the duplicate test and random tests. Everything else is ordered.

  • sadegh-moayedizadeh Avatar

    This kata was different from most katas I tried, more practical actually, I liked it so much. Too many random tests too, not a bad thing actually.

  • MikChan Avatar
  • Kacarott Avatar

    Array of colors in RGB format and its positions [[r, g, b], positoion]

    positoion

  • Kacarott Avatar
    • No random tests
    • Not even close to enough tests in total
    • You contradict yourself: number in range [0, 1] and for number < 0 return first color for number > 1 return last color.
      • (Why not just only pass numbers between 0, 1?)

    I genuinely think this is a cool idea for a kata (It seems to be unique as well). I strongly suggest you fix up the problems with it before more people start solving it and rating it badly just for the problems.

    • aland97 Avatar

      Thanks for your feedback. Added some random tests.

    • Kacarott Avatar

      The random tests look good. That marks off the first two of my points. The main issues now are in your description.

      1. You say that number is in range [0, 1]. As Johan said below, you should specify that it is a float. Also, if you say it is in the range [0, 1] then you should not be testing for other inputs.

      2. You do not specify what happens if the input number is not between two colours. For example if the lowest color is at position 0.2 but the input number is 0.1, you need to tell us how to handle that. Should it assume that the color at point 0 is black/white? Should it assume that there is no gradient, and that it should match the "lowest" colour? (Which is how it currently works). You just need to make it clear

      Also, as a side note, as you fix each issue, feel free to mark them as resolved (if they really are fixed)

    • Kacarott Avatar

      The description could still use a little formatting, but my main issues seem to be solved now.

      Issue marked resolved by Kacarott 4 years ago
  • JohanWiltink Avatar

    if two colors has a same positoion take last for numbers <0 return first color for numbers >1 return last color if array is empty return [0, 0, 0]

    Some linebreaks would really help here.

  • JohanWiltink Avatar

    It is unspecified how to gradient between colours in defined positions.

    I am pretty much done assuming things for this kata. Specify that sh!t !

  • JohanWiltink Avatar

    Apparently the position is a float between 0 and 1 ( at least in the primary input ). This should be specified; if nothing is specified integer is a reasonable assumption for the datatype ( R, G, B apparently indeed are integers ).

  • JohanWiltink Avatar

    No example tests.

  • JohanWiltink Avatar

    Please don't round. Ask for a floating point answer and test with a margin for error. See available documentation why and how.

    • JohanWiltink Avatar

      And this is why.

      Position: 0.9430000000000005
      Color Set:
      0.0062509: [ 142 203 35 ]
      0.1516516: [ 58 187 133 ]
      0.1601735: [ 24 198 209 ]
      0.1705400: [ 138 62 34 ]
      0.2448608: [ 46 100 113 ]
      0.2584741: [ 103 205 10 ]
      0.4570756: [ 39 41 117 ]
      0.4851606: [ 113 106 66 ]
      0.4910144: [ 177 90 254 ]
      0.4938313: [ 186 233 82 ]
      0.6313692: [ 39 159 160 ]
      0.7993191: [ 121 236 202 ]
      0.8148218: [ 104 254 36 ]
      0.9360975: [ 42 81 226 ]
      0.9608953: [ 172 52 226 ]
      0.9646473: [ 46 121 73 ]
      error: expected [ 78, 72, 225 ] to deeply equal [ 78, 72, 226 ]
      

      My solution is correct, and, with some repeated submitting, accepted. ( It doesn't show up in Solutions, but that's probably a CW error. You can see it by clicking View Solutions on any of my comments. )

    • JohanWiltink Avatar

      I genuinely think this is a cool idea for a kata (It seems to be unique as well). I strongly suggest you fix up the problems with it before more people start solving it and rating it badly just for the problems.

      I actually agree with this sentiment and think it's a crying shame I just voted "Totally unsatisfied" because you are handling floating point arithmetic really, really wrong.

      You have just invented the square wheel when round wheels have been documented for ages.

    • aland97 Avatar

      Position: 0.9430000000000005

      p1 0.9360975: [ 42 81 226 ] p2 0.9608953: [ 172 52 226 ]

      expected [ 78, 72, 225 ] to deeply equal [ 78, 72, 226 ]

      between p1 and p2 blue always equal 226

      but you last solution give corect result for this color set

    • aland97 Avatar

      i realy want to keep rgb as integers just like in RGB24

    • JohanWiltink Avatar

      I am not willing to discuss anecdotes. I copied that failure message straight from your submit tests, and you are handling floating point arithmetic wrong.

      I know I'm giving the correct answer. My solution is not the problem.

      Have you read applicable docs? If, after reading those, you do not understand how to do FP arithmetic in your kata, or why, I am willing to have a conversation.

    • JohanWiltink Avatar

      i realy want to keep rgb as integers just like in RGB24

      I understand that. But it can't be done, not in a CW kata. Do you understand why?

    • JohanWiltink Avatar

      You have just invented the square wheel when round wheels have been documented for ages.

      I just noticed "round wheels" is a very unfortunate turn of phrase .. :P

    • aland97 Avatar

      Do you understand why?

      not realy

    • aland97 Avatar

      CW kata

      What is mean?

    • Blind4Basics Avatar

      CW = codewars

    • JohanWiltink Avatar

      So, did you read applicable documentation?

    • aland97 Avatar

      Yes, I read. You are right. I do not really like this idea, but I will make changes.

    • aland97 Avatar
      Issue marked resolved by aland97 4 years ago
    • JohanWiltink Avatar

      Seems fixed correctly. Thank you.

      You don't have to like it, and I can see why you wouldn't.

      One way you can use rounding in a kata is by specifying a specific order of computations ( expression parsers can do this, and sometimes they do. and sometimes then then still get it wrong and allow an error margin ). Or you would have to use a +/- 1 delta, which gets a bit ridiculous, but still lets you specify integers. It's definitely a design time consideration, not an afterthought.

      Sorry I was right; I have an irritating tendency to do that sometimes. I try not to let it happen too often. Sometimes I succeed spectacularly. :P