Zig-zag matrix: Difference between revisions
→{{header|Haskell}}: Pruned a (now) redundant import, added signatures, tweaked name to avoid wiki glitch, preferred guards to if then.
m (→{{header|Haskell}}: Tidied mapAccumL version) |
(→{{header|Haskell}}: Pruned a (now) redundant import, added signatures, tweaked name to avoid wiki glitch, preferred guards to if then.) |
||
Line 2,149:
Computing the array:
<lang haskell>import Data.Array (Array, array, bounds, range, (!))
import Data.Monoid (mappend)▼
import Text.Printf (printf)
compZig :: (
compZig (x, y) (x_, y_) = compare (x + y) (
where
if even (x + y)▼
zigZag :: (Int, Int) -> Array (Int, Int) Int
zigZag upper = array b $ zip (sortBy compZig (range b)) [0 ..]
where
|