5 kyu
Convert A Hex String To RGB
6,085 of 15,601Krxtopher
Loading description...
Parsing
Strings
Algorithms
View
Career Accelerator
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.
2 => 16
Groovy Translation
This comment has been hidden.
Java: created fork which output value is HashMap, as stated in the description, and which resolves this issue.
P.S. The solutions with int[] shouldn't be invalidated, because backward compatibility for
int[]
has been implemented as well.Approved
Random tests + chai for JS
Chai + assert for CoffeeScript
Spec compliant Scala translation
approved :D
Swift: the structure can be changed by user so with some hijinks you can cheat out all tests (one of possible ways to do that is here).
P.S. OG issue by zLuki: here
I am only getting 8 points for this 5 kyu question, can someone help me out with this?
5 kyu tasks are worth 21 rank points and 8 Honor points, so it sounds correct.
Oh ok, thank you very much.
Interesting one though easier than I thought.
Thanks for the interesting task.
I don't get it. When I import java.util.HexFormat then it doesn't work. Is this import turned off or anything like that?
Waht version of JAva is
HexFormat
from, and what version of Java have you selected when submitting our solution?If anyone is having issues with Node 18 and it says "assertSimilar is deprecated, use deepEqual" you must do Test.assertDeepEquals :D
It seems to me that kyu lvl does not match at least for python)
TypeScript Translation ... for review / approval
Approved
I dont understand what should i return, map or array?
Read the post just below yours.
Java : description asks for a
Map<String, int>
but tests expect anint[]
.Fixed in latest fork
I find it a bit too easy for a 5kyu, and the java solution returns an int array, not a Map<String,int> I think it needs to be updated, it's deceiving
For the longest time I didn't understand what was going on. The explanation of Map<string,int> in the description is really really misleading for JavaScript, which actually makes you do horrificly verbose stuff as a beginner giving this a shot.
It's actually super simple, except for the output having to be absolutely specific with such misleading directions. Once I figured out what it was asking for, it finally accepted my code. I had to work around the solutions being locked to actually see what the issue was, though.
I don't understand what's your problem. Which changes would you suggest to improve the description?
This comment has been hidden.
Oh, in other news, since I "cheated" the first time to see the solutions (in an effort to see why my result wasn't being accepted) I've since done several variations I've saved in VScode. In that sense, this has been really educational to play around with different outputs.
Map<String, int>
seems clear to me. Moreover in case you have a doubt about the output, you should have a look at test cases to see examples. Here it's easy to see you have to return a dictionary/map and not a function.im having a problem with the output python! error message: Example Tests Log {'r': 255, 'g': 153, 'b': 51} None should equal {'r': 255, 'g': 153, 'b': 51}
im getting the right results but once i try to return it in the mandatory format its giving me an error. im returning a print of a string using format to have the 3 values of the tuple in the correct place. can anyone explain what the "return an object" means if it isnt suposed to return a string with the correct syntax?
You must return a dictionary, not a tuple, not a string, nor print anything. Have a look at the test cases.
thank you, i was sure i was not returning the correct object. i was able to do it ;))
Nice kata, but it would be better if it was 6th or even 7th kyu.
Completed in C. Looking through other solutions... here I am doing things the manual way! haha facepalm
Too easy for a 5kyu. I know it can't be changed. I just know you all love to read such remarks.
Still a fun kata though.
format() would have been way easier... Anyway... now I know little about map() as well even though it was not asked here ^^ The map<String,int> in the description has confused me alot.
This comment has been hidden.
Problems with your code are not a kata issue.
Please see if troubleshootig FAQ is helpful: https://docs.codewars.com/training/troubleshooting/
Who ever made swift must be kidding, you can just change the struct and cheat all the tests
What the reason to use integrated methods of hex parsing? LOL. Try to avoid using something like Int.parse()
bruh how tf is this 5th kyu
PHP translation to be reviewed
Ruby 3.0 should be enabled, see this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Done 👍
In its current state I would rate this as 7 kyu at most.
Look at the approval date
Ha, yes, I only heard afterwards that it could not be changed, unfortunately.
i'm no computer science major, but this challenge seems pretty easy for a 5kyu rating. I'd give it a 6kyu at most. Perhaps modifying it so the trainee has to deal with shorthand, or bad input may help increase the complexity? It's still a fun little puzzle, but there are puzzles in the 6kyu range that are tougher than this.
I think this should be rated as 6kyu since it is quite simple
ranks cant be changed
C translation available. Author inactive; please check and approve.
Can somebody help me? I am puzzled, I do not understand why it gives me an error Test Results: Expected: '{r: 255, g: 153, b: 51}', instead got: '' {r: 255, g: 153, b: 51} \ ''
there's a backslash in your result at the end
This comment has been hidden.
Your code returns a string instead.
thanks¡¡
Alguien me puede ayudar? Estoy desconcertado, no entiendo porque me da error Test Results: Expected: '{ r: 255, g: 153, b: 51 }', instead got: ''{ r: 255 ,g: 153 ,b: 51 }''
You got a space after each number and then a comma, invert the order put first the comma and then a space, thats all!
Tenes un espacio despues de cada nuemro y despues la coma, inverti el orden, pone primero la coma y el espacio despues, cambia eso y ya esta!
The description says to convert hex to rgb but Im getting this error: {'r': 15, 'g': 249, 'b': 2355} should equal {'r': 255, 'g': 153, 'b': 51}
The first value is what your function returned, the other is the expected value, none of them are the input value, you have to print it if you want to see what it is, and it'll appear above the test result.
oops yes i realized that now, thank you!
I'm a little confused as to why this is labeled 5 kyu? Is this much harder in languages that aren't python?
just because it's a very old kata.
Ranks of new katas are constantly devaluating over the years.
What? Don't you mean the ranks are increasing in value/difficulty? There are kata now that are much harder at 5 kyu than most old 5 kyu kata.
sorry, I tend to forget that the scale is reversed x)
=> over the years, new katas of the same difficulty are ranked "easier", hence with higher kyu value, yes.
Updated Ruby translation kumited -- please check and approve (note: author is inactive)
.
Python translation with random tests
Everything is fine. Approved!
Thanks for your work!
No, thank you!
No random tests for javascript (maybe for other languages too) and very few fixed tests.
Coffeescript and Swift are also missing random tests.
Coffeescript and Swift got their random tests by someone; the problem with JS still stands tho
Fixed in JS
Also updated test framework to chai.
Appears that all current languages have random tests, resolving.
Kotlin Translation
Please, review and approve/comment
This comment has been hidden.
This is a good exercise.
I would recommend, though, that there be an added "twist" where one should have to work with either 3-digit or 6-digit hex.
Please, do not use regex in such tasks and anywhere else where you can avoid them. They are much slower than other solutions.
Needs randomized tests. Remember to freeze the Math object.
Good feedback so far. I admit I was totally guessing at the level because I couldn't initially find a description of the levels. @arnedag, where is the description you reference in your comment? I have since found this documentation (https://docs.google.com/document/d/1eseD5xyhGdtQ-DaWdqfK2yf6mvTDWHWEpkQGBppI8cw/edit?pli=1) and based on its examples I would still probably argue that a kata like mine - which requires the use of bitwise operators which are a somewhat obscure and infrequently used language feature - would still qualify as probably a 3 kyu. That level cites "simple regex" as an example and, in my mind at least, bitwise operators are on par in complexity as simple regex. Would you agree or am I not thinking about this correctly?
The problems are:
A kata search for "bitwise" turned up three results. Two were set to 6 kyu and one was set to 3 kyu. I've changed the level of mine to 6 kyu. Does that seem like a fair valuation?
Also, can someone confirm for me whether this document is the right thing to reference when determining kata level?
Oh, and @delfuego, my intention is not to require the use of bitwise operators. However, I'm anxious to see the solutions people devise that don't use bitwise operators.
ALL of the solutions submitted so far don't use bitwise operators, unless some have come through since I last looked. Honestly, I'm not sure I would ever turn to them for this; it's making complexity where none is needed.
I'd say this is, at MOST, a 6, since it requires string manipulation and then either base conversion arithmetically or by using the radix argument in parseInt, both of which you might charitably argue are a bit more complicated than the standard 7-kyu fare.
Mmm, the bitwise approach should perform much much more quickly than the various non-bitwise solutions proposed, right? String parsing is always going to be slower than bitshifting and masking. Granted it adds complexity, but I wouldn't say none is needed - if you're trying to jam as many of these transforms as possible into a cycle the bitmath will pay dividends.
I wonder if it would be possible to define kata using performance constraints. Obviously you couldn't do it in an absolute sense, as different machines would perform differently, but perhaps providing a reference implementation (say, using string parsing) and requiring that any solutions perform better by a factor of X?
Putting in that kind of constraint would not only encourage more efficient solutions but would also justify a higher kyu by touching on meaningful performance metrics as a requirement rather than a hypothetical.
This comment has been hidden.
I agree with the 4-kyu level being way off.
Also, I'd make sure to state in the description that you're not expecting the users to be able to handle the shorthand HTML hex color descriptors (e.g.,
#FFF
as shorthand for#FFFFFF
).I also handled the three character hex descriptors, should be more explicit in the description ;)
I not an expert on the requirements of the various kyu levels, but level 4 is way off for this problem.
The description for level 7 lists (among other things):
which seems about right for this problem.
11 years later and I agree