Skip to content

Instantly share code, notes, and snippets.

@masylum
Created April 14, 2011 11:58
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 masylum/919335 to your computer and use it in GitHub Desktop.
Save masylum/919335 to your computer and use it in GitHub Desktop.
Haskell is cool
import Data.Char
import Numeric
rotate :: [a] -> [a]
rotate (x:xs) = xs ++ [x]
isRotated :: Eq a => [a] -> [a] -> Bool
isRotated xs ys = any (==xs) (take (length ys) $ iterate rotate ys)
binaryToChar :: String -> Char
binaryToChar = chr . fst . head . readInt 2 isDigit digitToInt
getPassword :: [String] -> [String] -> String
getPassword xs ys = foldl (\acc (x, y) -> if (isRotated x y) then acc ++ [binaryToChar x] else acc) "" (zip xs ys)
solve = getPassword ["01001100", "01101000", "01010000", "01010011", "01001001", "01000011", "01101000", "01101001", "01110110", "01101001", "01110000", "01101100", "01100010", "01000111", "01101000", "01111010", "01100101", "01111001", "01101101", "01100001"] ["10010001", "01011110", "01100101", "10011010", "10000010", "11110000", "11010000", "00101101", "11111000", "11010110", "11100000", "00011011", "01101110", "11110000", "01101100", "01101010", "11001010", "11001011", "01101110", "01110010"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment