RosettaCodeData/Task/Floyds-triangle/Miranda/floyds-triangle.miranda
2024-04-19 16:56:29 -07:00

27 lines
720 B
Text

main :: [sys_message]
main = [Stdout (lay (map floyd [5, 14]))]
floyd :: num->[char]
floyd n = lay (map fmt rws)
where rws = rows n
cws = map ((+1).width) (last rws)
fmt rw = concat (map (uncurry rjust) (zip2 cws rw))
rows :: num->[[num]]
rows n = rows' [1..n] [1..]
where rows' [] ns = []
rows' (l:ls) ns = row : rows' ls rest
where (row, rest) = split l ns
split :: num->[*]->([*],[*])
split n ls = (take n ls, drop n ls)
rjust :: num->num->[char]
rjust w n = reverse (take w (reverse (show n) ++ repeat ' '))
width :: num->num
width = (#) . show
uncurry :: (*->**->***)->(*,**)->***
uncurry f (a,b) = f a b