Anonymous user
User talk:Gaaijz: Difference between revisions
→Zigzag: improved version
(→Zigzag: improved version) |
|||
Line 12:
== Zigzag ==
Two different approaches with Haskell for the zigzag task.
antiDiags = unfoldr (\((c:cs),xs) -> if null xs then Nothing else Just (take c xs,(cs,drop c xs)))▼
transp_wof = unfoldr (\xs -> if null xs then Nothing else Just $ next xs)
next xs = (,) (concatMap (take 1) ks) ((map (drop 1) $ drop 1 ks) ++ ts)
where (ks,ts) = splitAt n xs
▲ dl = min m n
▲ antiDiags = unfoldr (\((c:cs),xs) -> if null xs then Nothing else Just (take c xs,(cs,drop c xs)))
▲ ([1..dl]++(replicate nd dl)++[dl-1,dl-2..0], [0..m*n-1])
▲ revcs = zipWith id (cycle [id,reverse]) antiDiags
:Slower version, almost complete emulation of the J-solution
groupon f x y= f x == f y
|