プログラミング言語論 中間テスト 解答例(2023 年度)


(1)
foo ((x, y):xs) | x > y  = y + foo xs
foo (_:xs)               = foo xs
foo []                   = 0
(2)
bar n = [ (x, y) | x <- [1..n], y <- [x..n], x * y `mod` 18 == 0]

(1)  [1,2,4,5,7,8]

(2)  [(2,1),(1,3),(3,-1),(-1,7),(7,-9),(-9,23)]

(3)  [2,4,5,8,10,14]

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