Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jvvk
Created August 19, 2014 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvvk/87b7d270fcfdaef8d1ed to your computer and use it in GitHub Desktop.
Save jvvk/87b7d270fcfdaef8d1ed to your computer and use it in GitHub Desktop.
Fogcreek hash problem
hash s h0 str = last $ scanl1 (\x y -> x*37 + y) (h0:[fromJust $ elemIndex c str | c <- s])
unhash h h0 str = reverse $ unfoldr (\x -> if x == h0 then Nothing else Just (str !! (x `mod` 37), x `quot` 37)) h
hash "leepadg" 7 "acdegilmnoprstuw"
unhash 680131659347 7 "acdegilmnoprstuw"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment