Skip to content

Instantly share code, notes, and snippets.

@bakhtiyork
Created February 6, 2016 09:28
Show Gist options
  • Save bakhtiyork/056f3c2bcb01d606f4f2 to your computer and use it in GitHub Desktop.
Save bakhtiyork/056f3c2bcb01d606f4f2 to your computer and use it in GitHub Desktop.
Reverse hash quest
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