module Sol11 where import HL11FAIS -- | 11.17 ball :: Int -> [[Int]] ball n = ballgame [n] ballgame :: [Int] -> [[Int]] ballgame xs | all (== 1) xs = [xs] | otherwise = xs : ballgame (reduce xs) where reduce (1 : ys) = 1 : reduce ys reduce (n : ys) = (n - 1) : (n - 1) : ys -- | 11.79 The function pair is nothing but the function j defined in Theorem 11.52. Here it is (to check that it is the inverse of natpairs, you can use map pair natpairs): pair (n, m) = (n + m) * (n + m + 1) `div` 2 + n -- | 11.79 First, we need code for enumerating N2 , N3 , . . . , as lists: natpairs2 = [(x, toInt z - x) | z <- [0 ..], x <- [0 .. z]] natlist 0 = [[n] | n <- [0 ..]] natlist k = [n : (natlist (k - 1) !! m) | (n, m) <- natpairs2] natstar = [] : [natlist n !! m | (n, m) <- natpairs2]