プログラミング・パラダイム(2017 年度)テスト解答例(一部)


(1)
  foo :: [Integer] -> Integer
  foo [] = 0
  foo (x:xs) = (if x `mod` 3 == 0 then 1 else 0) + foo xs
(2)
  bar :: Integer -> [(Integer,Integer)]
  bar n = [(i,j)| i <- [1..n], j <- [i..n], i * j `mod` 12 == 0 ]

(1) [0,1,1,2,3,5,8,13]
(2) [(2,2),(2,3),(2,4),(2,5),(3,2),(3,3),(4,2),(5,2)]