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


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

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