User talk:Gaaijz: Difference between revisions
Content added Content deleted
(→Zigzag: improved version) |
|||
Line 12: | Line 12: | ||
== Zigzag == |
== Zigzag == |
||
Two different approaches with Haskell for the zigzag task. |
Two different approaches with Haskell for the zigzag task. |
||
⚫ | |||
flist = map (:[]) |
|||
⚫ | |||
elist = cycle [[]] |
|||
⚫ | |||
⚫ | |||
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 |
|||
zigzag m n = transpose. map concat. transpose |
|||
. uncurry ((.(map (liftM2 (++) ((`take`elist).(`subtract`n).length) flist))).(++) |
|||
.(map (liftM2 (++) flist ((`take`elist).(`subtract`n).length)))) |
|||
$ splitAt k revcs |
|||
where |
|||
k = truncate . sqrt . fromIntegral $ (m*n) |
|||
⚫ | |||
nd = abs (m-n) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
:Slower version, almost complete emulation of the J-solution |
:Slower version, almost complete emulation of the J-solution |
||
groupon f x y= f x == f y |
groupon f x y= f x == f y |