5 kyu
RGB To Hex Conversion
48,368 of 136,914jhoffner
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.
This comment has been hidden.
Yes good, but nevertheless I was compelled to apply the spoiler flag to your comment because it revealed a piece of code relevent to solving the kata.
Please keep that in mind in regards to future comments, thank you.
I solved the kata but I did not receive any points, is this normal?
Sometimes (very rarely) points can appear with a delay. But if I see correctly, now all your points should be there.
hex colors inside tests are not compatible with actual standart color codes (JS) for example these:
doTest( 0, 0, -20, '000000'); // which aactually --> "000014"
Haskell translation
Groovy Translation
Approved
This comment has been hidden.
This happens because the tests are called multiple times (
Kata.Rgb(...)
), but you set up another static variable which doesn't get reset between these calls (it acts like a global variable).So you should either reset this variable at the start of
Rgb
function, or even better, just move that variable inside theRgb
function, and you won't have to worry about such things. In this case, you'd have to redesign your solution, so that, for example,Iterate
would return a List, which you could use in the originalRgb
method.@Tomeegar please read this: https://docs.codewars.com/training/troubleshooting#works-but-no
This comment has been hidden.
You will want to make sure that r, g, and b are numbers between 0 and 255. Try to work through what would happen if, for example, r equals 260.
It worked, what was happening is the b was getting negative value and due to this char1 and char2 were getting undefined. Thanks
This comment has been hidden.
It is ok on a beginner level, but then it should have 8 kyu rating if you ask me.
why does it happen? value which return my function ==> EFCC8B for r = 239 g = 12 b = 139: expected 'EFCC8B' to equal 'EF0C8B'
Your solution thinks that
12
isCC
, but it should be0C
.my function returns CC for 12
Yes, and this is wrong.
CoffeeScript: Missing sample test & random tests
added
Why doesn’t my solution work if everything is correct in vsCode, but in codewars it gives a different answer?
Because there are still some cases you might haven't thought of when you're testing your code on your own environment with your cases, but in codewars those edge cases you missed are tested. That's why your solution can pass your test in vs code, but not on codewars.
This comment has been hidden.
скорее всего нужно использовать return потому что ты должен возращать ответ
This comment has been hidden.
If you're not sure, don't use the
Issue
flag.Issue
flag is only used when something is wrong on the kata-side.FFFF12C
when the input isr = 255, g = 255, b = 300
. It should returnFFFFFF
.This comment has been hidden.
why and how does it influence?
This comment has been hidden.
Even if your code doesn't work, mark your post as having spoiler content next time. If your code times out, it probably has an infinite loop.
Hello !
Thanks for the advices, it was my first time here. I'll check for the suppose infinite loop, probably the while and a lack of int() for the divisions...! I'll be back when I get it !
This comment has been hidden.
This comment has been hidden.
How is this 5 kyu tho? Maybe lower it down to 6? because it's basically just string formatting and conditional statements
Solution worked on other IDE but here returns "r = 0, g = 0, b = 0 expected "��E�H�� ]�fD", but got "000000"" witch is more than confusing. Anyone else had the same issue if so what is the fix, i think i'm messing with the memory addresses that the test function uses. (in C)
See the initial code in C:
That's a problem with your code, not a kata issue, use
Question
label next time.r
,g
andb
can be negative. The format"%x"
takes an unsigned integer as input, so you are printing a very large number after reinterpretation of the signed int as un unsigned int. Since the output string has enough room for 6 characters + 1 nul terminator, you are writing out-of-bounds, which causes chaos in the tests suitsprintf(h, "%c", '\0');
appends 2 nul characters to the string, becausesprintf()
always nul terminates its target string after finishing the printing. same problem as above, you are writing out-of-bounds.
This comment has been hidden.
Completed kata just fine, but recieved this warning when doing random tests:
tests/Fixture.cs(37,17): warning CS0219: The variable 'Tests' is assigned but its value is never used
Marking as possible issue, but it could be totally inconsequential
I have the same issue due to this i am unable to solve this kata...
So your code isn't working due to this error? Mine worked just fine, it just had that error as well. Didn't seem to affect it at all, though, so I submitted it anyways.
This is a
warning
, not anerror
, it is not the source of whatever issue you are encountering.Author used 'Tests' variable in random tests but never used it. It's possible that the 'Tests' variable was intended for testing purposes, but as long as it doesn't impact the correctness of the code, you can safely ignore it.
Fixed.
im not sure if i wrote something incorrectly, but every time i press attempt theres always one random test that says it attempted to index a nil value, but when i print the input and test it in vs code, it returns the answer correctly?
Please post your code (don't forget to mark it as a spoiler) and tell us which test case is causing the error.
I'm getting this error when I test my code. Is it because of my code or the test? Traceback (most recent call last): File "/workspace/default/tests.py", line 2, in from solution import rgb ImportError: cannot import name 'rgb' from 'solution' (/workspace/default/solution.py)
You renamed the function from
rgb
torgb_to_hex
. Don't do that, simply implement the function body. The tests rely on the given name.oh I understand now. Thank you so much
doesn't work correctly in c++
Do you care to elaborate, or is that the sum total of your insight into this perceived issue?
I passed all the tests and whenever I tried to submit the Attempt, there will always be one error at the last attempt. This is a bug because the code is running smothly.
Print the input, your code is wrong.
That is by color, you're doing it wrong.
Thank you Chrono79 for the feedback, but my code is actually working fine as I implemented this too "Any values that fall out of that range must be rounded to the closest valid value." We are going to have only two cases for the above, in terms of rounding to the closest valid value (which will be either to 0 or 255)
In fact, whn I tried the error locally, it works fine. This is a bug from Codewars.
No, it's a bug in your code:
Your code should only round r to 255, not g and b to 255 too.
This comment has been hidden.
Look clearly at the error message you provided.
expected 'F22F7' to equal '0F22F7'
The expected answer is on the right side. The left side is the output of your function. So, the one that outputs the string with length 5 is your function. This is not kata issue.
Thanks for comment , I went back to recheck. I was so sure that I saw to equal with 5 digits. I managed to pass all tests now.
This comment has been hidden.
Your solution overflows the output buffer.
It's a bug in your solution, not a kata issue. There is even a sample test which makes it fail.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You're wrong, your code is wrong, the kata is fine:
Your code doesn't do that and no wonder it doesn't work. Tested with the same input your code fails everywhere. Not a kata issue, please read the description better next time so you don't waste your time. Read this too: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
Your code is wrong:
Not a kata issue.
This comment has been hidden.
Fixed.
I don't get it, my code works in other IDEs but doesn't in this one. It shows: r = 0, g = 0, b = 0 expected "000000", but got "@@@@@@@�@" but when i test in others it actually shows 000000
Thats because you changed the signature of the function. You need to keep it as it is in initial solution setup.
I am using JavaScript My solution working on vs code. But it is not working here. I am using toString method to convert rgb to hex. Is the problem related to node version?
Your solution fails for specific kind of inputs mentioned in specs. You need to make sure your solution is able to handle all types of specified inputs.
Your solution has a bug. Bugs in your solution are not a kata issue.
This comment has been hidden.
This one was really fun!
I hate quesitons like this that go too deeply into some random problem. Grumble grumble lol
Isn't this too easy to a 5kyu, or it's just easy for golang ?
I thought it was pretty easy as well, and I did C#
Though I suppose it's up to the mods. They've been on this site longer, they're probably better at gauging difficulty than we are
didn't work on the following argument array: 181,181,267: expected 'B5B510B' to equal 'B5B5FF'
wrong tests
In what language?
Your solution has a bug, most probably a copy/paste mistake.
Bugs in your solution are not a kata issue.
C fork
Approved
I'm having problems with the tests... I check the output I get on Google color picker and the values are correct, but the test here says something else
Your code is wrong, negative values should be converted to the next valid value. Not a kata issue.
Test was crashed after attempt
It's not funny when tests not to similar like task
What do you mean?
Tests crash it is unclear on what. All values are correct, but the tests do not pass.
What language?
sorry, I didn't look at the comment. I was just print, and your tests want to return))
Make sure to thoroughly read the details and remember what RGB can and cannot be.
why in Visual Studio when I debug the code, it displays the correct results for all tests, and here it says:Actual: "000000010203"?
OP solved it, closing
Nice kata :)
Doesn't work here even though it works on node, I run a loop so the resulting string should be consistent every iteration but it somehow returns undefined at the last iteration
Not a kata issue, your code fails with the test with negative numbers.
this challenge doesn't work as it should be. I got this error message while testing: Test Failed Expected string length 6 but was 7. Strings differ at index 4. Expected: "FFFFFF" But was: "FFFF12C" ---------------^ but in Visual Studio it's OK. Please, fix this problem. Plus, I think this challenge can't be 5 kyu, should be 6 or even 7 in my opinion.
That is a problem with your code and we can't fix it.
I got same thing
should not be a 5 k
I agree, it's a bit easy for 5kyu
Why i recieved only 8 points instead of 28 ?
Read this
WHen I try to Test on Typescript I get an error:
TSError: ⨯ Unable to compile TypeScript: test.ts:7:5 - error TS2552: Cannot find name 'Test'. Did you mean 'test'?
7 Test.assertEquals(rgb(0, 0, 0), "000000")
Same.
Same here.
I'm not familiar with chai so not claiming this is the best fix, but replacing the basic tests with this gets it working
Fork and fix waiting for approval.
Solved. Closing.
C: the return type should be
void
.Fixed
[Swift] The test is not working properly because shows all the time that the answer is not correct even though it is - cannot finish the task. Repair it please
Are you sure? I just tested my solution: Time: 2101ms Passed: 4Failed: 0
The tests are fine, your code is not.
In C. I have wrote to the output variable. When I print it, it holds the correct information but the tests say the output variable is empty.
output = testing;
- it is not how output arguments work in C.Your solution is not entirely correct, it's not a kata issue.
This comment has been hidden.
TypeScript Translation ... For review / approval
Sample tests are wrong, change
Test.assertEquals
forassert.strictEqual
to fix them.my solution doesn't work with full-range tests but it passes all other tests, I am confused, cuz it says if value is out of range round it to the closest value
Your solution returns incorrect answers for
rgb(300, 300, 300)
orrgb(-10, -10, -10)
.Currently in Python, if the builtin
hex
function is overriden, obscure errors will be raised and the kata's reference solution (a one-liner) will be printed out in the traceback.There are numerous comments related to this, for example: 1, 2, 3, 4, 5
Here's a fork to fix this.
Approved.
This comment has been hidden.
That's a problem with your code, not a kata issue. Your code fails the last sample test, figure out why. Read this: https://docs.codewars.com/training/troubleshooting
D translation
Update to Scala 3
Approved by someone
This comment has been hidden.
Yes, such things happen when your code is wrong and your results are not correct.
Did you try to run your code in a local IDE? Did you try to run your solution twice in a row?
You need to fix a bug and try again to submit it to Codewars.
i'm trying on https://play.kotlinlang.org/ and sending good code to Codewars. maybe problems there?
You are not sending good code to Codewars. Your code is wrong.
I've written a lot of code to solve this task :(
wtf. 80% of solutions not working now. lol. how did they pass the tests?
Which language are you talking about?
JS
Probably more tests were added at some point and solution's revalidation didn't trigger. I've revalidated the first 30 or so, so all of those should be fine.
The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) https://docs.microsoft.com/en-us/dotnet/api/system.windows.media?view=windowsdesktop-6.0
This comment has been hidden.
You must put quotes around
fmt
. Not a kata issue.This comment has been hidden.
Maybe it's a matter of PHP version? This (somewhat old) post suggests that support for local funcitons in PHP is... uhhh.... PHPy.
Moving the local funciton to the global scope makes the solution work.
In PHP, all declared functions are global. So every time
rgb
is called,hex
will be defined in the global scope. The second time you callrgb
, it will try to definehex
again in the global scope and will produce an error becausehex
is already defined. The same thing occurs on your other hosting site if you try to run more than one test at a time (just add one moreprint rgb(148, 0, 211);
after your first one on the other site and you'll see).Thx Bob. I found solution (use anon funcs):
$hex = function ($x) {...} ... return $hex($r).$hex($g).$hex($b);
Works.
Great kata imo. Good for reminding you to READ the specs carefully.
I think it would make it easier to format the paragraph a bit. Not a criticism: arguably it's better as-is.
Errors in testing data:
In sample test rgb value is -20,275,125 and hex 00FF7D but correct hex for this rgb value is #14ff7e
you can check it with google color picker
another test data incorret too
Sorry for my bad english)
-20 is clamped to 0 (refer description).
not a kata issue
T_T
Language - C Execution Timed Out (12000 ms) I don't know, what's a problem :/
Your code is too slow, or it gets lost in some infinite loop. I you haven't done it already, I suggest you to have a look there: https://docs.codewars.com/training/troubleshooting/
yes, I read that this means that the code seems to be slow, I slightly disagree with this statement. Can I show the code? I tried to modify my code with returning a pointer on array (on my machine works well), and here site show me such result: 00��;�
OP solved the kata
This comment has been hidden.
This is not sufficient at all to raise an issue. Your code returns "0000undefinedundefined", which is obviously a bad answer. Please read carefully this: https://docs.codewars.com/training/troubleshooting
Apologies, this is my first time commenting. It ended up being an issue on my end for handling edge cases; thanks for your response.
This comment has been hidden.
found it just ok, could provide more context
Hi! In VSCode and GO.Playground my code works, but in CW i have an error:
STDERR
codewarrior/kata
kata_test.go:9:6: expected 'IDENT', found '='
But I can't find any explanation for the error anywhere.
In sample tests, the 9th line must be replaced by:
(You can edit the tests yourself). I published a fork fixing it but it needs to be approved first.
You are the best. Thank`s
Julia: sample tests don't test anything.
fixed
Hello guys !!
I'm having some problems here because in the tests
Got: FFFFFFECFF7D | Expected: 00FF7D
but in VScode got00FF7D
with the same code.In VScode i'm defining the array output[7] and it's working fine but not here, maybe that's the problem
If someone could help i appreciate it (:
PS: I can send the code for here if someone wants see. Very ez to read i would say.
Read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
And have you tested your function with negative values?
This comment has been hidden.
Ooo wait it worked now with the negative values :/ (in sample testes)
But now its given this error Got:
FF0CFFFFFF7D | Expected: FF0C00
and in VSCode is givingFF0C00
What am i missing ? xD
Check your else ifs.
Forget it ! Thank you so much :)
Maybe its the hours xD
Appreciate it
Golang Sample Tests code lacks "_" in line 9 "var = Describe("Test Example", func() {"
Fixed in this new fork: https://www.codewars.com/kumite/625f781c3b6ad4005cbbd90f?sel=625f781c3b6ad4005cbbd90f
Please review and approve if it's ok.
Next time, you may also give the corrected line (I'm not familiar with Go tests framework and I don't have a clear mind in the early morning, so I had to look at another kata to find the fix) :)
Fixed.
I guess it needs to me repaired.
I've got the same messages as the others:
Testing for 280, 120, 390
Expected string length 6 but was 7. Strings differ at index 2. Expected: "FF78FF" But was: "FF000FF"
done this in Visual Studio 2022 works perfectly fine
Please read carefully this documentation before raising issues: https://docs.codewars.com/training/troubleshooting/
Thanks @akar-0 I found a mistake in my Code.. I split the result of my calculation into 2 integers by the char "," (european standards) but the Coma in the american standards is "."
There is a problem in the python version: After the sample tests as you can see here : #output of test results Test Passed Test Passed Test Passed Test Passed Test Passed Testing random values: -43 ,3 ,-42: '000300' should equal '000000' Testing random values: 187 ,239 ,45: 'BBEF2D' should equal '000000' Testing random values: -76 ,201 ,248: '00C9F8' should equal '000000' Testing random values: 114 ,241 ,33: '72F121' should equal '000000' Testing random values: 97 ,-79 ,131: '610083' should equal '000000' as you can see RGB(187,239,45) is expected to be '000000' in HEX Which is absurd and so are the other assertions. Please fix this
You're overwriting a built-in. There is nothing to fix but your code.
COBOL translation + description unified.
Can't to approve due to a conflict in the description. I created a fork with the correct description.
Thanks!
Python version has an input including a G value of 275, not doable.
Input with value of 275 for G conforms to the spec. Please read instructions carefully.
I think the python ver has a bug. Keep getting this error eventhough i don't use 'rgb' anywhere in my solution:
Traceback (most recent call last): File "tests.py", line 3, in test.assert_equals(rgb(0,0,0),"000000", "testing zero values") NameError: name 'rgb' is not defined
I've tested all cases separately in VScode and all work.
That is what the kata ask you to make the
rgb
function, don't change the initial setup, should be:def rgb(r, g, b):
got it - thanks! I think the initial setup had def hex_to_rbg(hex) which might have been what caused the problem
This comment has been hidden.
This kata has been solved more than 25000 in JavaScript, so it's very unlikely the kata has a problem, you're probably doing something wrong (and in all cases nobody can check anything since you give no concrete element). I advice you to read carefully the documentation: https://docs.codewars.com/training/troubleshooting/
The C++ solution template has a Java-style class with no members that is never instantiated. That is highly unidiomatic C++.
fixed
testing out of range values: '00007D' should equal '00FF7D' sample text is test.assert_equals(rgb(-20,275,125), "00FF7D", "testing out of range values")
-20 and 275 are out of range values but 275 counts as 255
lang python
Your function returned the first wrong value, the other is the expected one.
Yes, I studied the question while I was doing it. The code should equate to 'FF' values that are greater than 255. I thought that if the value is greater than 255, then it should be considered as an error (I mean '00')
Can't get it done, I think the Python version may have bugs
Testing random values: 154 ,192 ,20: '9AC014' should equal '040200'
Pal, I finally did it in JS. 0000-14 meant negative number. lol
Check you're not overwriting a built-in. The tests are fine.
Do not quote understand why do I get "expected '0000-14' to equal '000000'" when i .join ('00', '00', '00') - it works in jfiddle but now here
I struggled here - you have to round up any minus numbers and round down any numbers over 255
It has bugs, because of given sample expect(rgb(255, 255, 255), equals('FFFFFF')); expect(rgb(255, 255, 300), equals('FFFFFF')); expect(rgb(0, 0, 0), equals('000000')); expect(rgb(148, 0, 211), equals('9400D3')); expect(rgb(148, -20, 211), equals('9400D3')); expect(rgb(144, 195, 212), equals('90C3D4')); expect(rgb(212, 53, 12), equals('D4350C')); using dart language
There is no issue.
.
But description clearly says what to do when some value is out of 0-255 range.
my bad(
way too easy for 5kyu tbh
This is broken. Random tests always expect "000000". (in Python)
No, because if that was true, this would pass all random tests and it doesn't:
Maybe you're overwriting some built-in, check that.
I tried that, and they passed
But yeah renaming the function to something else then 'hex' fixed it
I had the same problem, very obscure that you cannot name your function hex... I mean, I get the problem, but how should one know...?
did anyone go the zfill way?
good one !
I've seen some pretty good and elegant solutions (better than mine), there, congratz everyone!
This comment has been hidden.
Which language are you talking about here?
same thing with JS. Works perfectly fine in console but shows an error here with '000000'
No, because if that was true, then this should pass all random tests:
maybe something out of function
I do not feel like i earned that 5 kyu XD Too easy, probably should be 7 kyu
(C# 7.3) One of the tests on Attempt throws an error:
Fixed.
src/Solution.cs(11,27): error CS0117: 'Convert' does not contain a definition for 'ToHexString'
OP solved it, closing
I cannot understand why (212,53,12) test instead of D435C should be D4350C. In task is written that answer should always be 6 characters long, but anyway O before 12?
It's not O, it's 0
This comment has been hidden.
Should be more than 6kyu convertions are easy in coding
maybe some people just don't know how to convert it
ha that is what i said
This comment has been hidden.
Read the error message you get, your validator method has a little mistake.
Thanks i find error
Very good kata which lets you revise the fundamentals of IT ! If you forgot or never knew how to convert a base 10 number to base 2 or 16 then i strongly recommend to not use some specific programming language in-built functions that does all the work for you. I think these functions must be forbidden since the goal is to write the whole algorithm yourself and not use a piece of code that solves the whole thing for you.
I now have an idea how to do this, thank you for the comment ! Are there any good resources you would recommend that treat this subject ?
That would certainly be more cerebral.
However, where do you draw the line? Writing you own upperCase, min, max, etc functions? If the language supports it, out of the box, then it's out there to be used.
This comment has been hidden.
This comment has been hidden.
I think you should limit below 0 and upper 255
i wrote a code that returns the right value in my code editor but a '0' when i attempt the code here and it comes with an error why?
me too i have the same problem !!!
We can't guess what's wrong (and in javascript there is no problem with the tests, so it's your code's problem), please read this: https://docs.codewars.com/training/troubleshooting/ If you're still sure there is a problem, provide your code following those instructions.
how the F i am supose to know how to convert rgb to hex !! at least explaine -_-
The same way you convert any base to another. Alternatively, you'd need to do research and... you know... learn. :)
fine !! i'll search :(
For anyone looking through the comments maybe even 2 years later like me, Here is some more info. Nothing concise or well written just some notes that may help you. It isn't anything close to an answer but should help hopefully.
00-09 - 00, 01, 02 ... 09 10-15 - 0a, 0b, 0c, 0d, 0e, 0f 16 - 25 - 10, 11, 12, 13, ... 19 26 - 31 - 1a, 1b, 1c, ... 1f 32 - 41 - 20 ... 29 42 ... 255 - 2a ... ff
There's a big issue with the description of this kata. It state that the answer should always be 6 chars long and what the test is expecting is no where near it. for JavaScript
expected '000' to equal '000000'
Kindly fix it. Or atleast correct the description.
Your code returned
'000'
the expected value is'000000'
and it has 6 digits, fix your code.Yeah! you are right. My bad. Misunderstood the language, thanks for correcting me.
What exactly do u mean by 'Any values that fall out of that range must be rounded to the closest valid value.' Super vague. Do u mean make the variable positive if its negative? Or do u mean make the variable 0 if its out of range? What defines a valid value? I know how to code the solution, just dont quite get what u mean by that. Cheers.
If it's less than 0, it should become 0. If it's greater than 255, it should become 255.
Got it, thank u so much!
Clojure error in solution setup:
change the ns to
(ns rgb.core)
Also missing
defn
in the rgb function definition.that works, author should adapt snippet
the initial code compiles now
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
anyone else using C have issues with the random tests? The kata keeps getting garbage values as the result. But if I'm going through and printing each converted character as the program continues... the hex values are correct. For some reason, when it submits, it turns into garbage. I'm only having this issue in the randomly generated tests. I'm not sure if it is connected but there are all sorts of compiler flags in the randomly generated tests.
It's hard to tell without seeing your code, but it's most probably caused by your solution. My guess goes on returning a pointer to a stack memory.
The random tests are OK, although there are compiler warnings.
Do you remember to zero-terminate your string? (I don't know how you're generating your string)
Yeap. And I verified that the output pointer is null terminated by printing out the int value of the 6th index of the output *(output + 6)... and that is null terminated for each one.
I don't get SIGSEV issues or overflow issues. The output is just showing "??????". I can copy and paste my code and mark is as spoiler?
Yes: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#post-discourse
This comment has been hidden.
I had the same problem (С code). Most likely the problem is garbage in array output. I solved it output[0] = '\0';
This comment has been hidden.
This comment has been hidden.
When building C code compiler returns this mistake: fixture.c: 16: 20: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare] for (int i = 0; i <input_sz; i ++) ~ ^ ~~~~~~~~ Can be easily fixed either by adding 'unsigned' into the for loop or by deleting unsinged from input_sz variable.
I encountered this too.
FIxed in list of C katas to update
This comment has been hidden.
Please, post your code in a comment with a spoiler tag. The only reason I can think of why this is happening is that you're overwriting some functions globally.
... oh, that would do it. I didn't know that
hex
was a built-in, so I had this defined globally:Thanks for the help!
C++ Does not work, Basic tests are fine, but all random tests expect values as if green was 0.
C++ tests seem to be fine.
Oh, Perhaps i'm missing something then.
The basic tests work fine, but none of the random ones do. I put some logs in to the code - as you can see here https://imgur.com/a/quZ5I95
Every random test results the same thing, my debugs display a (seemingly correct?) logical progression to a non-0 Hex value, but then the expected value always has the green value as 00.
Seeing your code would help too.
This comment has been hidden.
From all the things which are wrong with your solution, the wrongest ones are probably buffer overflow and missing includes.
I'm not claiming my code is perfect by any means - I'm here to learn after all.
But my terrible code shouldn't change the expected values? The first print in my first screenshot was the first line in the function
the expected values are still 0, which is what my original issue was for
Unfortunately, in C and C++ things are not that easy.
Invalid memory access is defined in C++ as a cause of undefined behaior, and this can mean anything. In your case, your solution writes outside of the result buffer and modifies something which is later on used to calculate reference solution, or to print the message, or anything else. When undefined behavior happens, there are no guarantees anymore: anything can change, anything can break, even things apparently unrelated.
If I were to guess,
sprintf
puts null terminator right behind your buffer, and probablyg
variable happens to be located there on the stack, messing up further computations. But it's just guessing, and it can be wrong or can change from run to run.This comment has been hidden.
Please don't post solutions in Discourse.
C++ random tests do not work at all...
fixed
This comment has been hidden.
I might be wrong but i think your code returned '000000' while the expected result is 'F00E40'...
This comment has been hidden.
https://catb.org/~esr/faqs/smart-questions.html#explicit
Regarding the NASM version
From the Details section :
The tests use negative numbers, which we're supposed to set to 0. They are however not 64 bit values as the use of rdi/rsi/edx/rcx indicate, but 32 bit values. testing whether the numbers are below zero makes little sense when the sign bit is bit 31 instead of 63.
It's also not clear from the description that we're supposed to return the pointer to the string - which we're supplied in rcx. The Details does not mention this, the tests does not indicate it, but the C-prototype indicate it. I had a lot of chrashing until I figured it out.
(it's the Details/description part I think needs fixing, not the kata itself).
I have made an attempt to clarify by updating the description.
Out of all the 5 kyu I have done, this one had to be the easiest by far. Even without built-in neat tricks like in Javascript which make base-hopping absolutely trivial. Oh well, guess I at least learnt something about RGB conversion.
Hello, i don't understand this error mesg in python : quote : "testing near zero values: '112233' should equal '010203' " 11 should not equal 01 22 should not equal 02 as well as 33 not 03 !
The first of those two values is what your function wrongly returned, not the input, if you want to see the input, print it.
It might be worth including that the hex system is just the base 16 colors of RBG strung together. It took a minute to find that information about how hex colors relate to RBG.
This comment has been hidden.
Because of this:
And please mark your post as having spoiler content next time.
okey! thanks! i m new here, my next question will be marked as spoiler
After trying to submit.
main.rb:13:in
+': no implicit conversion of Array into String (TypeError) from main.rb:13:in
check' from main.rb:25:in `That's a problem with your code, it's not returning a string.
Nevermind ;)
Why does the kata include tests with numbers not used in the RGB system?
https://www.youtube.com/watch?v=hhI4x6hx21s
according to the video the numbers should be between 0 - 255 cannot be more...
It's specified in the description what to do with those values, so not an issue:
C++ random tests seem to be expecting green to be 00 in every case
fixed
Why should numbers smaller than 0 or greater than 255 be considered valid input? Doesn't make sense to me
The kata is limited to a string of length 6. So 2 chars for R,G,B each. The maximumm number you can represent in hex (base 16) with two chars is 16^2 = 256
Not only is this wrong, because we start counting with 0, therefore maximum is 255, but it is also not an answer to my question.
I agree! The kata has wrong tests the numbers of RGB must be between 0 and 255 no more and certainly not negatives
video explains the RGB system v v v https://www.youtube.com/watch?v=hhI4x6hx21s
This comment has been hidden.
Had a issue with this kata, my c# code works perfectly in vs, but does not work here. Most of the return values are similer i.e Expected: "FFFFFF" But was: "FFFF12C". I am confused as this is not what it returns in my compiler.
And what was the input value? That seems like a problem with your code, not a kata issue.
Check your code does that.
No answer, closing.
This comment has been hidden.
This comment has been hidden.
Added.
I don't think using Python's built-in hex formatting code
02X
should be allowed. This is an #algorithms challenge; people should be writing the algorithm for this conversion, not using built-ins.I just learned of Python's built in "hex" function and was originally planning to use this, but am also simultaneously working on a solution that is hard coded. Unfortunately, it's just going to appear a little messy with me having to specify conditions regarding the Hex table.
This comment has been hidden.
in other editors it gives a answer different from here.
Still, you must trust this site for the correct testing. Your foreign environment cannot know all the tests, and anyway it is 99% probably incorrect if it doesn't match. If you want someone to check out your code, you may post it with proper markdown and remember to use a spoiler tag. Then someone can help you with your code.
in JS (at least)
this solution should not pass
random tests do not create sufficient cases such as
it remains untested as to whether other languages have the same issue
the main problem was the almost complete lack of random tests (only 1). I rewrote the tests suite, this solution does not pass anymore
I think that task should be considered completed when all main requirements are done instead even if 99% of the test requirements are correct and resting 1% is not the test is incomplete. That's a bit harsh don't you think?
It's useful to know that an important part of writing good algorithms is knowing that there are usually going to be edge or corner cases that can be extremely rare yet must be managed for the algorithm to be reliable.
The problem is with the test itself sometimes when you refresh the page it gives you different amount of correct answers. I managed to randomly pass lol =)
Very simple, felt more on par with a level 6 Kata, but great fun nonetheless. Enjoyed trying to make my solution as short and elegant as possible.
The ruby test cases were hilarious, all of it were error. even though you solved it, you cannot submit it because of this silly test cases make it not a valid answer.
I think you meant, there are no sample test in Ruby, because you can click Attempt and if your code is ok, pass the tests:
Fixed.
imo the rgb value should just be given as an array instead of three seperate arguments
The tests dont make sense. Given that rgb values can only be 0-255, any integer above or below should not be in the tests or the tests should expect a nil output. Instead we are getting this test, "Expected rgb(300, 255, 255) to return 'FFFFFF'" which is technically not possible given that 300 wouldnt be a valid rbg value.
From the kata description:
Not a kata issue.
This should be a 7kyu problem
nope, it shouldnt be. it works with classes, so its not that simple
My c++ code keeps failing in random tests, but in online compilers and in my pc works perfectly, also if I try testing the same input in tests and it's correct, don't know what happens :P
Not an issue. Your solution must be wrong.
Well, that's embarrassing, I noticed that I made a wrong validation heh, my bad.
it happens to me too
This comment has been hidden.
ofcourse. This is why you use google and mdn or other docs
There is a problem with this kata on JavaScript, it works well on my pc but fails on codewars so I just solved it with python.
And what would be the "problem"?
It seems it's a problem in your code rather than in the kata.
Your code is wrong, it fails with input like
12, 12, 12
. Maybe there is no test like that in Python.Okay, Thanks
Solutions on kotlin return error: expected:<000[000]> but was:<000[]>, but my solutions is correct - I tested it!
If you solution is correct, then why doesn't it pass the tests?
The result should always be 6 digits long, the shorthand is not allowed here. I've made it clearer in the description.
I'm getting: Testing random values: 67 ,118 ,-4: '437600' should equal '000000', which can't be correct.
Maybe you're overwriting a built-in function, and that's why it happens.
No answer after 2 months, closing.
Had the same issue, renamed my funcion "hex()" to "to_hex" and then it worked. Thanks!
This comment has been hidden.
really? You're giving me confidence to talk this. I have to understand hex code first though
This comment has been hidden.
Ranks can't be changed.
Agreed. I think it's a 7kyu without the negative/above 255 check, and with those checks a 6kyu (also for understanding hex).
In ruby this kata always fails no matter what you input. I can run my algorithm on my machine and get the right answer every time. However, it always throws an error message when I enter the same code here.
There is an issue related with translating my dart code to js. I did everything correctly and the result is just what it is already written in the sample and random tests but it shows to me that my output isn't the same!. I also tested my code through dartpad and the result is correct.
My code doesn't work is not a kata issue, show your code marking your post as having spoiler content and we'll take a look. Almost 10k people has passed the kata in js.
No answer after two months, closing.
"didn't work on the following argument array: 195,165,88 - Expected: 'C3A558', instead got: 'FFFFFF'"
I don't think it's a kata issue, post your code, mark your post as having spoiler content so we can check if it works perfectly or not.
This comment has been hidden.
Don't use global vars, they keep their value between tests, so your code only works ok 100% the first time it is called and by chance in the next calls. It's a problem with your code, not a kata issue.
Too easy for 5 kyu. I think, it should be 6 or 7 kyu.
I DO think so too
Is this really a 5 kyu? It seems way too easy for that category.
Elixir translation awaiting approval. Includes 100 random tests.
Python 3.x should be enabled.
My code (C++) passes the sample tests, yet, when I attempt the whole kata, it says the BasicTests are passed, but exits with code 132 (without even attempting any random test or something else).
SampleTests : Time: 1849ms Passed: 1 Failed: 0
Test Results: ExampleTests (green arrow); BasicTests (green arrow);
Kata Attempt: Time: 2146ms Passed: 1 Failed: 0 Exit Code: 132
Test Results: ExampleTests (RED arrow); BasicTests (green arrow);
Retried it several times and it ended up working...
All the Python random test cases only return true when output = "000000", regardless of the input RGB values.
You're overwriting a built-in function, and that's why it happens.
Ah, thank you sensei.
This comment has been hidden.
Don't override built-in functions.
Thankyou!!
C# tests passed with warning:
"tests/Fixture.cs(37,17): warning CS0219: The variable 'Tests' is assigned but its value is never used"
Factor translation
Approved
This comment has been hidden.
10 о 10
Greetings, i tried to submit the solution of RGB To Hex Conversion, but when i do it, the application does not take it, but it still gives me the points
This comment has been hidden.
This comment has been hidden.
sorry, but your issue doesn't make any sense:
'01137D' should equal '00FF7D'
means that your code returned the first, but should have returned the latterso obviously, you're using your output as input in your reasonning, so no issue here. ;)
Note :
issue
== problem in the kata itself (tests, description,...). With almost 20 000 completions, well... unlikely to happen.question
== user having a problem solving the kata. => That's you currently.cheers
PS: print the inputs to the console to see what your code is actually doing with what.
Thanks alot! Sorry, I didn't know all the nuances about tests, but now it's clear for me.
nice kata for formatting practice
PHP translation is available for review.
This comment has been hidden.
If there is already a translation (this case) you can't add another one. When the translation is not approved yet, you can fork it. If you have enough honor points (not sure how many) you can edit a kata if there are issues open.
thank you. got it.
Rust translation ready for review.
Already approved
Scala translation available for review.
Already approved
This was a good kata! It made me learn the zfill function in python.
This test does not work for C#
My implementation in Visual Studio returns FFFFFF, but here FFFF12C returns
Not a kata issue as 3k++ ppl completed it. Perhaps u should consider RGB values are from 0-255.
This comment has been hidden.
And how do you know that your code is definitely correct?
Should throw some nulls, undefineds, numbers as strings, 0xFF etc. values into the tests. There are a lot of solutions where the usual dodgy input that we get in production would cause them to fall over, and as is it's a bit easy for 5 kyu.
Lua random tests: Expected objects to be the same. Passed in: (string) '03FFCD' Expected: (string) '3FFCD'
Without random: Expected: (string) '000000'
Random wants me to cut the zeros, but not random does not want
The issue with 0-padding has been corrected. The expected value should now be '03FFCD'.
This comment has been hidden.
The issue with 0-padding has been corrected. The expected value should now be '0C9384'.
Random tests seem broken for python:
Testing random values: 261 ,143 ,55: 'FF8F37' should equal '000000'
Testing random values: 322 ,-36 ,248: 'FF00F8' should equal '000000'
Testing random values: -39 ,193 ,190: '00C1BE' should equal '000000'
Testing random values: 331 ,38 ,80: 'FF2650' should equal '000000'
Testing random values: -223 ,236 ,16: '00EC10' should equal '000000'
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Added.
Should be 7-8 kyu not 5
My Python code works fine on my end and returns the correct number based on the sample test but I get 8 of 10 errors so not sure what the issue is. My Python version is 3.7 but that should not be issue, I guess.
Simple but awesome kata
C# test cases are broken. For rgb(255, 255, 255) it says my algortihm returns FFFF2C but testing it on my own my algorithm returns FFFFFF.
Over 1000 people have completed the C#. It is near impossible to know if your code has a problem or is correct if you don't post your code with markdown (use a spoiler tag).
In my opinion, the javascript tests are furthermore failing to check for illegal arguments like any "NaN". Either have them checked or exclude them in the task description.
Kotlin : The sample tests expect 6 digit hex values but the random tests are expecting 5. A RGB hex needs 6 digits to be valid. This error is only occuring when the value is between 10 and 16, e.g. it will expect 'F' instead of '0F'.
A hack is to put an additional check but it should be this way.
Already reported. Please scroll a bit further to see my request.
The sample tests for JavaScript are just the placeholder tests left by Codewars when creating a Kata.
Fixed.
I am getting this error every time I try with Python:
```STDERR: Traceback (most recent call last): File "main.py", line 1, in from solution import * File "/home/codewarrior/solution.py", line 3
SyntaxError: invalid syntax```
That's seems a problem with your code, not a kata issue, also check this:
Paste your code and mark your post as having spoiler content.
Also note that the version available for Python is 2.7.6, maybe you're trying to use something that doesn't work there.
In Kotlin:
Expected <FFF8C>, actual <FF0F8C>.
It should be always string with 6 chars.
The problem seems to be when any r, g or b value is between 10 and 16 it drops the preceeding '0' eg. 10(dec) -> A(hex) instead of 0A(hex). So a quick fix is to just add a case for when the value is between 10-16 and drop that 0.
I don't know what you changed, but I tried resubmit solution and still have this error
java.lang.AssertionError: Expected <FFFFB>, actual <FFFF0B>.
This comment has been hidden.
This comment has been hidden.
A question, not an issue, and read the instructions again:
And also:
This comment has been hidden.
Or your solution breaks something.
Kotlin Translation
Please, review and approve/comment
Already approved.
Issue above.
This comment has been hidden.
a example(2,263,140) Expected objects to be the same. Passed in: (string) '02FF8C' Expected: (string) '2FF8C'
but why the result of example(0,0,0) is '000000' not '00000'
You didn't mention which language. But for the Lua translation, the issue with 0-padding has been corrected. The expected value should now be '02FF8C'. Other languages may still exhibit the issue.
Julia translation kumited :)
Already approved
Lua Translation
Please review and approve :)
Already approved
I'm using c# and I keep getting:
It seems to always be the blue. I have tested the blue by itself and it's fine. It is even fine with two values, but when I add a third, the blue gets "12C". I even did two blues and got "FFFF" and I added a green and got "12C12CFF".
I have tried different formatting techniques and the same problem exists. Any idea? Thanks!
that's not an issue, pay attention to b value,hint: you need to have some limit for the values :D
I actually do put upper (255) and lower (0) limits on what the values should be. I even tested my code on my IDE and it passes fine.
Very strange, the code is working in codewars today. Perhaps something was mixed up with my browser. I have rebooted since, and it works.
Please, NASM Translation
Already approved
The tests are not sufficient check for expected output. In the instructions, input:(0,0,0) has an expected output of '000000'.
EXPECTED: It follows then, that input:(4,4,4) should have an expected output of '040404'.
THE PROBLEM: However if student returns output of '444', this Kata (incorrectly) passes.
TO FIX THIS: Please add a test to ensure that single digit values for any color channel is padded with a '0' so it is 2 digits long !
Could also check that the length of every string is 6 characters, though this alone would not ensure that any padding is done correctly.
ALTERNATE "FIX": -OR- edit the instructions to indicate that (0,0,0) could/should return '000'.
This comment has been hidden.
Yes, Javascript.
No: '444' passes their tests. But it should pass only if transformed to: '040404'.
Adding a test for (4,4,4) => '040404' should be added. (or something similar..)
Checking for 6 chars would be a help, though not quite sufficient, as '000444' could also pass that test..
added proper random tests.
This comment has been hidden.
Dude's traceback prints out the kata's reference solution.
Everyone can see it, for four years...
You overwrote the builtin hex function.
This comment has been hidden.
Java translation added :)
I believe the Python version has a bug in the solution file. When I try and run a sample test, I get:
'Traceback (most recent call last): File "main.py", line 1, in from solution import * File "/home/codewarrior/solution.py", line 14
SyntaxError: invalid syntax'
That error is shown when you try to run the empty initial code. I've tested it (with functional code) and it works. Maybe show your code in a post and mark it as having spoiler content if you require better help.
I've added
pass
to initial code to avoid the confusing error.Swift translation kumited.
Please carefully review and approve. Test structure based off of F# traslation
@jhoffner, awesome kata! But as always! :)
The JavaScript Kata does not have randomized tests so you can just pass the 4 answers following the input
Random tests were added.