Jump to content

Zig-zag matrix: Difference between revisions

m
→‎{{header|Haskell}}: Tidied mapAccumL version
m (→‎{{header|Haskell}}: Tidied mapAccumL version)
Line 2,193:
 
zigZag :: Int -> [[Int]]
zigZag = horizontalsgo <*> diagonals
where
diagonalsgo n_ [] = []
go n xss = (head <$> edge) horizontals: go n (dropWhile null (tail <$> edge) ++<> rst)
let slope = [1 .. n - 1]
in snd $where
(edge, mapAccumLrst) = splitAt n xss
 
(\xs h ->
diagonals :: Int -> [[Int]]
let (grp, rst) = splitAt h xs
diagonals n =
in (rst, bool id reverse (0 /= mod h 2) grp))
snd $ mapAccumL go [0 .. (n * n) - 1] (slope <> [n] <> reverse slope)
where
(slope ++ [n] ++ reverse slope)
horizontalsslope = [1 .. n xss- 1]
go xs h in= (rst, bool id reverse (0 /= mod h 2) grp))
| null xss = []
| otherwise =where
let (edgegrp, rst) = splitAt nh xssxs
in (head <$> edge) :
horizontals n (dropWhile null (tail <$> edge) ++ rst)
 
main :: IO ()
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.