User talk:Gaaijz: Difference between revisions
Content added Content deleted
(→Jers) |
|||
Line 13: | Line 13: | ||
Two different approaches with Haskell for the zigzag task. |
Two different approaches with Haskell for the zigzag task. |
||
flist = map (:[]) |
flist = map (:[]) |
||
elist = |
elist = cycle [[]] |
||
revNrev True = cycle [reverse,id] |
|||
revNrev _ = cycle [id,reverse] |
|||
transpN True = id |
|||
transpN _ = transpose |
|||
zigzag m n = |
zigzag m n = transpose. map concat. transpose |
||
. uncurry ((.(map (liftM2 (++) (elist.( |
. uncurry ((.(map (liftM2 (++) ((`take`elist).(`subtract`n).length) flist))).(++) |
||
.(map (liftM2 (++) flist ((`take`elist).(`subtract`n).length)))) |
|||
$ splitAt k revcs |
$ splitAt k revcs |
||
where |
where |
||
Line 26: | Line 23: | ||
dl = min m n |
dl = min m n |
||
nd = abs (m-n) |
nd = abs (m-n) |
||
⚫ | |||
rev = m<n |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
groupon f x y= f x == f y |
groupon f x y= f x == f y |
||
tab n = fst . until (null.snd) (\(xs,ys)-> (xs++[take n ys], drop n ys)) . (,) [] |
tab n = fst . until (null.snd) (\(xs,ys)-> (xs++[take n ys], drop n ys)) . (,) [] |
||
Line 39: | Line 34: | ||
where fdiag = map (map snd). groupBy (groupon fst).sortBy (comparing fst) |
where fdiag = map (map snd). groupBy (groupon fst).sortBy (comparing fst) |
||
$ zip (map sum $ sequence [[0..m-1],[0..n-1]] ) [0..] |
$ zip (map sum $ sequence [[0..m-1],[0..n-1]] ) [0..] |
||
*Main> sum.map sum $ zigzag 500 500 |
*Main> sum.map sum $ zigzag 500 500 |
||
1185103928 |
1185103928 |