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

@ -0,0 +1,37 @@
import Data.List (mapAccumL)
import Data.Text (justifyRight, pack, unpack)
zigZag :: Int -> [[Int]]
zigZag n = horizontals n (diagonals n)
where
diagonals :: Int -> [[Int]]
diagonals n =
snd $
mapAccumL
(\xs h ->
let (grp, rst) = splitAt h xs
in ( rst
, (if mod h 2 /= 0
then reverse
else id)
grp))
[0 .. (n * n) - 1]
(slope ++ [n] ++ reverse slope)
where
slope = [1 .. n - 1]
horizontals :: Int -> [[Int]] -> [[Int]]
horizontals n xss =
if not (null xss)
then let (edge, rst) = splitAt n xss
in (head <$> edge) :
horizontals n (dropWhile null (tail <$> edge) ++ rst)
else []
main :: IO ()
main =
putStrLn $
unlines $
(concat . (unpack <$>)) . ((justifyRight 3 ' ' . pack . show) <$>) <$>
zigZag 5