RosettaCodeData/Task/Floyds-triangle/Haskell/floyds-triangle-1.hs
2017-09-25 22:28:19 +02:00

17 lines
406 B
Haskell

import Control.Monad (liftM2)
floydTriangle =
liftM2
(zipWith (liftM2 (.) enumFromTo ((pred .) . (+))))
(scanl (+) 1)
id
[1 ..]
alignR :: Int -> Integer -> String
alignR n = (\s -> replicate (n - length s) ' ' ++ s) . show
formatFT :: Int -> IO ()
formatFT n = mapM_ (putStrLn . unwords . zipWith alignR ws) t
where
t = take n floydTriangle
ws = map (length . show) $ last t