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


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

(1)  28
(2)  [(1,1),(2,1),(2,2),(3,2),(3,3),(4,3),(4,4),(5,5),(6,6)]