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

21 lines
991 B
AutoHotkey

n = 5 ; size
v := x := y := 1 ; initial values
Loop % n*n { ; for every array element
a_%x%_%y% := v++ ; assign the next index
If ((x+y)&1) ; odd diagonal
If (x < n) ; while inside the square
y -= y<2 ? 0 : 1, x++ ; move right-up
Else y++ ; on the edge increment y, but not x: to even diagonal
Else ; even diagonal
If (y < n) ; while inside the square
x -= x<2 ? 0 : 1, y++ ; move left-down
Else x++ ; on the edge increment x, but not y: to odd diagonal
}
Loop %n% { ; generate printout
x := A_Index ; for each row
Loop %n% ; and for each column
t .= a_%x%_%A_Index% "`t" ; attach stored index
t .= "`n" ; row is complete
}
MsgBox %t% ; show output