Created
February 6, 2016 09:28
-
-
Save bakhtiyork/056f3c2bcb01d606f4f2 to your computer and use it in GitHub Desktop.
Reverse hash quest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abc = "acdegilmnoprstuw" | |
pnum = 37 | |
-- Solution 1 | |
reverse_hash1 _ 0 = [] | |
reverse_hash1 x len = (reverse_hash1 x' len') ++ [abc !! m] | |
where | |
m = x `mod` pnum | |
x' = (x - m) `div` pnum | |
len' = len - 1 | |
-- Solution 2 | |
reverse_hash2 x len = map (abc !!) (base [] x) | |
where | |
base a x | |
| x == 0 = a | |
| x == len = a | |
| otherwise = base (r:a) q where (q,r) = x `divMod` pnum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment