RosettaCodeData/Task/Floyds-triangle/Haskell/floyds-triangle-1.hs

18 lines
406 B
Haskell
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
import Control.Monad (liftM2)
2013-04-10 21:29:02 -07:00
2017-09-23 10:01:46 +02:00
floydTriangle =
liftM2
(zipWith (liftM2 (.) enumFromTo ((pred .) . (+))))
(scanl (+) 1)
id
[1 ..]
2013-04-10 21:29:02 -07:00
2017-09-23 10:01:46 +02:00
alignR :: Int -> Integer -> String
alignR n = (\s -> replicate (n - length s) ' ' ++ s) . show
2013-04-10 21:29:02 -07:00
2017-09-23 10:01:46 +02:00
formatFT :: Int -> IO ()
formatFT n = mapM_ (putStrLn . unwords . zipWith alignR ws) t
where
t = take n floydTriangle
ws = map (length . show) $ last t