リストとか
Scalaでやってたやつとか。
- 平方数
> take 10 $ zipWith (*) [1..] [1..] [1,4,9,16,25,36,49,64,81,100] > take 10 $ map (\x -> x * x) [1..] [1,4,9,16,25,36,49,64,81,100]
- 総和と総積
> foldl (+) 0 [1..10] 55 > foldl (*) 1 [1..10] 3628800 > foldl1 (+) [1..10] 55 > foldl1 (*) [1..10] 3628800
- 追記:FizzBuzz
fizzbuzz = map f [1..] where f x = case (mod x 3, mod x 5) of (0,0) -> "FizzBuzz" (0,_) -> "Fizz" (_,0) -> "Buzz" _ -> show x
> take 20 fizzbuzz ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz","16","17","Fizz","19","Buzz"]
インデントにはまるなどしていた。