Zig-zag matrix: Difference between revisions
Content deleted Content added
Line 153:
=={{header|AppleScript}}==
<lang AppleScript
set R to {} -- Create a list with n-items (array).
repeat with i from 1 to n
set end of R to {}
end repeat
set {v, d, i} to {0, -1, 1}
repeat
if length of R's item i < n then
set {end of R's item i, i, v} to {v, i + d, v + 1}
if v ≥ n ^ 2 then exit repeat
if i < 1 then
set {i, d} to {1, -d}
else if i > n then
set {i, d} to {n, -d}
else if i > 1 and (count of R's item (i - 1)) = 1 then
set d to -d
end if
else
set {i, d} to {i + 1, 1}
end if
end repeat</lang>
<lang AppleScript>-- Code for outputting array in a nice table.
repeat with i in R
repeat with j in i
set j's contents to (characters -4 thru -1 of (" " & j)) as string
end repeat
set end of i to return
end repeat
return return & R as string</lang>
=={{header|AutoHotkey}}==
|