main = print $ mat [5,6,2,1,2,3] mat ns = take (maximum ns) (mat' ns) where mat' xs = map (> 0) xs : mat' (map (subtract 1) xs)