Skip to content

Instantly share code, notes, and snippets.

@geekingfrog
Last active August 29, 2015 14:14
Show Gist options
  • Save geekingfrog/9aba1a96b81eb1afcbd6 to your computer and use it in GitHub Desktop.
Save geekingfrog/9aba1a96b81eb1afcbd6 to your computer and use it in GitHub Desktop.
Trello hash haskell
-- the "hash" is actually a number in base 37, starting at 7
-- and digits are less than 15
data Letter = A | C | D | E | G | I | L | M | N | O | P | R | S | T | U | W deriving (Eq, Ord, Bounded, Enum, Show, Read)
-- point free and obfuscated version for demo purpose
reverseHash :: Int -> [Letter]
reverseHash = tail . reverse . map (toEnum . (`mod` 37)) . takeWhile (/= 0) . iterate (`div` 37)
main :: IO ()
main = do
let target = 956446786872726
let decomposition = takeWhile (/= 0) . iterate (`div` 37) $ target
let result = map (toEnum . (`mod` 37)) decomposition :: [Letter]
-- tail is here to remove the first digit which is 7 (the initial value)
let finalResult = tail $ reverse result
putStrLn $ "Result is " ++ (concat $ map show finalResult)
putStrLn $ "Result with point free version (should be the same): " ++ (concat $ map show $ reverseHash target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment