Created
February 17, 2013 22:56
-
-
Save yashigani/4973940 to your computer and use it in GitHub Desktop.
すごいH本読書会 in 大阪#2の練習問題を解いた
This file contains 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.Char (toUpper, intToDigit) | |
import Data.List (concat, words, tails, isPrefixOf) | |
upperCase :: String -> String | |
upperCase = map toUpper | |
removeSpace :: String -> String | |
removeSpace = concat . words | |
cover :: Eq a => [a] -> [a] -> Bool | |
cover lst1 lst2 = foldr (\x acc -> if (lst1 `isPrefixOf` x) then True else acc) False $ tails lst2 | |
uniq :: Eq a => [a] -> [a] | |
uniq = foldr (\x acc -> if (x `elem` acc) then acc else x:acc) [] | |
binExp :: (Integral a, Show a) => a -> String | |
binExp 0 = intToDigit 0:[] | |
binExp 1 = intToDigit 1:[] | |
binExp n = (binExp $ n `div` 2) ++ (show $ n `mod` 2) | |
main = do | |
print $ upperCase "Hello World" | |
print $ removeSpace "Hello World\nI'm John." | |
print $ [2..4] `cover` [1..4] | |
print $ [2..6] `cover` [1..4] | |
print $ uniq [1, 2, 1, 7, 6, 2, 4, 8] | |
print $ binExp 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment