html
html
1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
<title>Challenge 51</title>
</head>
<body>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var a = [], b = prompt("Enter size of matrix:") - 0;
for (var c = 0; c < b; c++) {
a[c] = [];
for (var d = 0; d < b; d++)
a[c][d] = -1;
}
var e = 0;
var f = 0, g = 0, h = "u";
while (e < b * b) {
if (g < b - 1 && h === "u") {
a[f][g++] = ++e;
if (g === b - 1 || a[f][g + 1] !== -1) {
h = "f";
continue;
}
} else if (f < b - 1 && h === "f") {
a[f++][g] = ++e;
if (f === b - 1 || a[f + 1][g] !== -1) {
h = "d";
continue;
}
} else if (g > 0 && h === "d") {
a[f][g--] = ++e;
if (g === 0 || a[f][g - 1] !== -1) {
h = "b";
continue;
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run