Zig-zag matrix: Difference between revisions
Content deleted Content added
m →Turtle style: tidy up |
|||
Line 5,452:
=={{header|R}}==
{{trans|
<lang
j <- seq(n)
{▼
▲ if(i > 1) i <- i - 1
if(j > 1) j <- j - 1▼
}▼
}▼
}
zigzag1(5)
zigzag(5)</lang>▼
zigzag2 <- function(n) {
a <- zigzag1(n)
v <- seq(n - 1)^2
for (i in seq(n - 1)) {
a[n - i + 1, seq(i + 1, n)] <- a[n - i + 1, seq(i + 1, n)] - v[seq(n - i)]
}
{{out}}
<pre> [,1] [,2] [,3] [,4] [,5]
[1,] 0 1 5 6 14
[2,] 2 4 7 13 15
[4,] 9 11 17 20 22
[5,] 10 18 19 23 24</pre>
=={{header|Racket}}==
|