September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,12 +1,17 @@
import Data.List
import Control.Monad
import Control.Arrow
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
alignR n = (\s -> replicate (n - length s) ' ' ++ s) . show
floydTriangle = liftM2 (zipWith (liftM2 (.) enumFromTo ((pred.). (+)))) (scanl (+) 1) id [1..]
formatFT n = mapM_ (putStrLn. unwords. zipWith alignR ws) t where
t = take n floydTriangle
ws = map (length. show) $ last t
formatFT :: Int -> IO ()
formatFT n = mapM_ (putStrLn . unwords . zipWith alignR ws) t
where
t = take n floydTriangle
ws = map (length . show) $ last t

View file

@ -0,0 +1,21 @@
import Data.List (mapAccumL)
floyd :: Int -> [[Int]]
floyd n =
snd $
mapAccumL
(\start row -> (start + succ row, [start .. start + row]))
1
[0 .. pred n]
-- TEST -----------------------------------------------------------------------
showFloyd :: [[Int]] -> String
showFloyd xs =
let padRight n = length >>= (<$> mappend (replicate n ' ')) . drop
in unlines $
(concat .
zipWith ((. show) . padRight) ((succ . length . show) <$> last xs)) <$>
xs
main :: IO ()
main = mapM_ putStrLn $ (showFloyd . floyd) <$> [5, 14]