11
The challenge is simple
Write a script that, when given a string input, will hash the string using the MD2 hashing algorithm, and then return either a positive integer or negative integer output based on which character set below is more common in the resulting hash as a hexadecimal string:
01234567 - (positive)
89abcdef - (negative)
- The input will always be a string, but may be of any length up to 65535
- The entire input, whitespace and all, must be hashed
- For the purposes of this challenge, the integer 0 is considered neither positive nor negative (see tie output)
- The more common set is the one who's characters are more common within the 32 character hexadecimal hash string
- Your output may contain trailing whitespace of any kind, as long as the only non-whitespace characters are a valid truthy or falsey output
- In the event of a tie, where the hexadecimal string contains exactly 16 characters from each set, the program should output a 0
I/O Examples
Input: "" (Empty String)
Hash: 8350e5a3e24c153df2275c9f80692773
Output: 1
Input: "The quick brown fox jumps over the lazy cog" (Without quotes)
Hash: 6b890c9292668cdbbfda00a4ebf31f05
Output: -1
Input: "m" (Without quotes)
Hash: f720d455eab8b92f03ddc7868a934417
Output: 0
Winning Criterion
This is code-golf, fewest bytes wins!
1It would be good to link to or ideally explain the MD2 hashing algorithm in the challenge specification to make it self contained. – Martin Ender – 2017-04-19T15:28:02.277
@MartinEnder Will do! – Skidsdev – 2017-04-19T15:29:58.500
I think it would be fair to simply accept three distinct values for win, lose, and tie – math junkie – 2017-04-19T15:45:12.883
@mathjunkie true, probably shouldn't be changing the spec so much, but I guess just having 1, 0 or -1 is the best way – Skidsdev – 2017-04-19T15:47:35.757
Hi there! Since others haven't mentioned it yet, I'll toss out a recommendation to use the Sandbox for future challenges, where you can get meaningful feedback and tighten up the challenge before posting on Main.
– AdmBorkBork – 2017-04-19T15:56:20.497@AdmBorkBork Ah thanks! Had I know about that I'd've definitely done so before posting it, will keep that in mind for the future, thanks! – Skidsdev – 2017-04-19T15:59:42.417
"are a valid truthy or falsey output" Shouldn't it be a valid integer...? "Your output may contain trailing whitespace of any kind, as long as the only non-whitespace characters..." The first part says trailing whitespace is allowed, but the second part implies leading and trailing whitespace are allowed. Which is it? – jpmc26 – 2017-04-19T22:15:29.133
2
This strikes me as a chameleon challenge. Either your language has a build-in or library to do MD2 and the rest is simple character counting, or it doesn't and you have to implement it yourself.
– xnor – 2017-04-20T00:20:24.460@xnor A lot of challenges are trivial in some language and difficult in others. Take the reciprocal challenge for instance... Many languages already have a function for this or at least support division. Some answers are in languages that don't and those answers seem to generally get more attention. It all comes down to not upvoting trivial solutions
– Poke – 2017-04-20T13:41:35.590