Skip to content

Instantly share code, notes, and snippets.

@yashigani
Created February 17, 2013 22:56
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 yashigani/4973940 to your computer and use it in GitHub Desktop.
Save yashigani/4973940 to your computer and use it in GitHub Desktop.
すごいH本読書会 in 大阪#2の練習問題を解いた
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