Created
November 10, 2012 13:44
-
-
Save yashigani/4051100 to your computer and use it in GitHub Desktop.
すごいH本読書会 in 大阪 #1 練習問題
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
-- ex1 | |
-- my null | |
null' xs = xs == [] | |
-- my sum | |
sum' xs = if null' xs then 0 else head xs + sum' (tail xs) | |
-- my product | |
product' xs = if null' xs then 1 else head xs * product' (tail xs) | |
-- my elem | |
elem' x xs = not (null' [y | y <- xs, x == y]) | |
-- slice from python | |
slice n m xs = drop n (take m xs) | |
-- ex2 | |
-- フィボナッチ数列のn番目を返す | |
fib n = if n == 1 then 1 else if n == 2 then 1 else fib (n - 1) + fib (n - 2) | |
-- FizzBuzzのn番目からm番目を返す | |
fizzBuzz n m = slice n m [if fizzBuzz n then "FizzBuzz" else if buzz n then "Buzz" else if fizz n then "Fizz" else show n | n <- [1..], let fizz x = x `mod` 3 == 0, let buzz y = y `mod` 5 == 0, let fizzBuzz z = fizz z && buzz z] | |
-- ex3 | |
-- good integral numbers | |
goodIntegrals = take 4 [n | n <- [100..999], let split n = (read [h], read [t], read [o]) where (h:t:o:_) = show n, let (a,b,c) = split n, c /= 0, n `mod` (10 * a + b + c) == 0, n `mod` (10 * b + a + c) == 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment