Created
October 19, 2015 04:54
-
-
Save motokiee/12e5c21e67f6f2692d6e to your computer and use it in GitHub Desktop.
モジュールとかMaybe使って色々遊ぶ的なやつ #CodePiece
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 | |
| wordNums :: String -> [(String, Int)] | |
| wordNums = map (\ws -> (head ws, length ws)) . group . sort . words | |
| isIn :: (Eq a) => [a] -> [a] -> Bool | |
| needle `isIn` haystack = any (needle `isPrefixOf`) (tails haystack) | |
| encode :: Int -> String -> String | |
| encode offset msg = map (\c -> chr $ ord c + offset) msg | |
| decode :: Int -> String -> String | |
| decode shift msg = encode (negate shift) msg | |
| digitSum :: Int -> Int | |
| digitSum = sum . map digitToInt . show | |
| firstTo40 :: Maybe Int | |
| firstTo40 = find (\x -> digitSum x == 40) [1..] | |
| firstTo :: Int -> Maybe Int | |
| firstTo n = find (\x -> digitSum x == n) [1..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment