RosettaCodeData/Task/Zig-zag-matrix/Groovy/zig-zag-matrix-3.groovy
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

5 lines
204 B
Groovy

def zz = { n ->
(0..<n*n).collect { [x:it%n,y:(int)(it/n)] }.sort { c->
[c.x+c.y, (((c.x+c.y)%2) ? c.y : -c.y)]
}.with { l -> l.inject(new int[n][n]) { a, c -> a[c.y][c.x] = l.indexOf(c); a } }
}