We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The instructions say the hex numbers may be three or six digits in length. It specifically shows some examples of invalid numbers that are between those two lengths, using four digits.
However, I see many people using patterns in their regexes like this…
[0-9a-f]{3,6}
That would match hex numbers 3, 4, 5, or 6 digits long. The HackerRank tests apparently do not include numbers with 4 or 5 digits, though, because that pattern passes all tests!
Better patterns that meet the requirements in the instructions could be…
([0-9a-f]{6}|[0-9a-f]{3})
([0-9a-f]{3}){1,2}
Each of those would match hex numbers 3 or 6 digits long, but not those with 4 or 5 digits.
This shows that it's not wise to follow all the requirements for each challenge. Code for the simplest case, then test it with the "Run Code" button. When code passes that simple test case, try using the "Submit Code" button. If the code fails any of those tests, then try improving the code to follow more requirements or spend a few Hackos to see the test case and code for that.
Is it the intention of the HackerRank admins to accept code that fails to follow the requirements? I don't know, but it seems to be working to the advantage of the users. Or is it? Maybe users end up learning the wrong lesson from the challenges instead.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hex Color Code
You are viewing a single comment's thread. Return to all comments →
OMG!
HackerRank's tests for this challenge are so lax!
The instructions say the hex numbers may be three or six digits in length. It specifically shows some examples of invalid numbers that are between those two lengths, using four digits.
However, I see many people using patterns in their regexes like this…
That would match hex numbers 3, 4, 5, or 6 digits long. The HackerRank tests apparently do not include numbers with 4 or 5 digits, though, because that pattern passes all tests!
Better patterns that meet the requirements in the instructions could be…
Each of those would match hex numbers 3 or 6 digits long, but not those with 4 or 5 digits.
This shows that it's not wise to follow all the requirements for each challenge. Code for the simplest case, then test it with the "Run Code" button. When code passes that simple test case, try using the "Submit Code" button. If the code fails any of those tests, then try improving the code to follow more requirements or spend a few Hackos to see the test case and code for that.
Is it the intention of the HackerRank admins to accept code that fails to follow the requirements? I don't know, but it seems to be working to the advantage of the users. Or is it? Maybe users end up learning the wrong lesson from the challenges instead.