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


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

(1) [2,8,18,32,50,72]
(2) [(3,3),(4,2),(4,4),(6,2),(6,3)]