Skip to content

Instantly share code, notes, and snippets.

@david-hodgetts
Last active August 29, 2015 13:56
Show Gist options
  • Save david-hodgetts/9328362 to your computer and use it in GitHub Desktop.
Save david-hodgetts/9328362 to your computer and use it in GitHub Desktop.
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