Last active
August 29, 2015 13:56
-
-
Save david-hodgetts/9328362 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Data.List | |
import Data.Char | |
numUniques :: (Eq a) => [a] -> Int | |
numUniques = length . nub | |
wordNums :: String -> [(String, Int)] | |
wordNums = tuplize . group . sort . words | |
where tuplize xs = map (\ all@(x:_) -> (x, length all) ) xs | |
isIn :: (Eq a) => [a] -> [a] -> Bool | |
needle `isIn` haystack = any (needle `isPrefixOf`) (tails haystack) | |
encode :: String -> Int -> String | |
encode s offset = map fuzzify s | |
where fuzzify c = (chr . (+ offset) . ord) c | |
decode :: String -> Int -> String | |
decode s offset = map unFuzzify s | |
where unFuzzify c = (chr . (subtract offset) . ord) c | |
numToDigits :: Int -> [Int] | |
numToDigits = (map read) . (map (\x -> [x])) . show | |
magicNum :: Int | |
magicNum = head [ x | x <- [1..], (sum . numToDigits) x == 40 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment