Created
November 30, 2012 11:54
-
-
Save ikedaisuke/4175351 to your computer and use it in GitHub Desktop.
Some answers of the homework in the slides
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
-- http://koko-u.github.com/haskell_book_reading/#25 | |
import Data.Char (toUpper, intToDigit, isSpace) | |
import Data.List (isInfixOf, nub) | |
import Numeric (showIntAtBase) | |
upperCase :: String -> String | |
upperCase = map toUpper | |
removeSpaces :: String -> String | |
removeSpaces = filter (not . isSpace) | |
-- cover almost equals isInfixOf | |
cover :: Eq a => [a] -> [a] -> Bool | |
cover = flip isInfixOf | |
uniq :: Eq a => [a] -> [a] | |
uniq = nub | |
-- http://stackoverflow.com/questions/1959715/how-to-print-integer-literals-in-binary-or-hex-in-haskell | |
binExp :: Int -> String | |
binExp x = showIntAtBase 2 intToDigit x "" | |
hanoi = undefined -- skip at the moment | |
fib :: Int -> Integer | |
fib n = fibs !! n | |
where fibs :: [Integer] | |
fibs = 0 : 1 : zipWith (+) fibs (tail fibs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment