6 kyu
Linear Color Gradient
37 of 80aland97
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
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.
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.
C++ translation
positoion
fix
number in range [0, 1]
andfor number < 0 return first color
for number > 1 return last color
.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.
Thanks for your feedback. Added some random tests.
The random tests look good. That marks off the first two of my points. The main issues now are in your description.
You say that
number
is in range[0, 1]
. As Johan said below, you should specify that it is afloat
. Also, if you say it is in the range[0, 1]
then you should not be testing for other inputs.You do not specify what happens if the input
number
is not between two colours. For example if the lowest color is at position0.2
but the input number is0.1
, you need to tell us how to handle that. Should it assume that the color at point0
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 clearAlso, as a side note, as you fix each issue, feel free to mark them as resolved (if they really are fixed)
The description could still use a little formatting, but my main issues seem to be solved now.
Some linebreaks would really help here.
Hey! Thanks for your feedback, I've improved the description a bit. Now is it clear what is required to perform this kata?
Ehm, no, not yet. Should the return value really be a function from a colour value to a position?
added an example of use
Yeah, that example is inconsistent with
rainbowGradient
isf
but over all colours at once, right?my bad. its totaly wrong. the solution should be similar to https://developer.mozilla.org/ru/docs/Web/API/CanvasRenderingContext2D/createLinearGradient, but with 1 dimension and no changeable after creation
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 !
fix
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 ).
Fixed.
No example tests.
Seems to be fixed.
Please don't round. Ask for a floating point answer and test with a margin for error. See available documentation why and how.
And this is why.
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 clickingView Solutions
on any of my comments. )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.
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
i realy want to keep rgb as integers just like in RGB24
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.
I understand that. But it can't be done, not in a CW kata. Do you understand why?
I just noticed "round wheels" is a very unfortunate turn of phrase .. :P
not realy
What is mean?
CW = codewars
So, did you read applicable documentation?
Yes, I read. You are right. I do not really like this idea, but I will make changes.
fix
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