foo2 [] = [] foo2 (x:xs) = if x > 0 then x : foo2 xs else foo2 xs foo1 [] = 0 foo1 [x] = x foo1 (x:xs) = x `min` foo1 xs foo xs = foo1 (foo2 xs) -- 別解 foo [] = 0 foo (x:xs) = let rest = foo xs in if x < 0 then rest else if rest == 0 then x else x `min` rest(2)
bar n = [(i,j) | i<-[0..n], j<-[0..n], (2*i+j) `mod` 3 == 0 ]Ⅱ