50 lines
772 B
JavaScript
50 lines
772 B
JavaScript
var level = 1;
|
|
var x = 0;
|
|
var y = 0;
|
|
var grid = [[1]];
|
|
function tryFind(x, y){
|
|
if(!grid[x]){
|
|
return 0;
|
|
}
|
|
if(!grid[x][y]){
|
|
return 0;
|
|
}
|
|
return grid[x][y];
|
|
}
|
|
function calcSquare(){
|
|
if(!grid[x]){
|
|
grid[x] = [];
|
|
}
|
|
var square = 0;
|
|
square += tryFind(x + 1, y);
|
|
square += tryFind(x + 1, y + 1);
|
|
square += tryFind(x, y + 1);
|
|
square += tryFind(x - 1, y + 1);
|
|
square += tryFind(x - 1, y);
|
|
square += tryFind(x - 1, y - 1);
|
|
square += tryFind(x, y - 1);
|
|
square += tryFind(x + 1, y - 1);
|
|
grid[x][y] = square;
|
|
console.log(square);
|
|
console.log(x, y);
|
|
}
|
|
while(level < 5){
|
|
while(x < level){
|
|
x++;
|
|
calcSquare();
|
|
}
|
|
while(y < level){
|
|
y++;
|
|
calcSquare();
|
|
}
|
|
while(x > -level){
|
|
x--;
|
|
calcSquare();
|
|
}
|
|
while(y > -level){
|
|
y--;
|
|
calcSquare();
|
|
}
|
|
level++;
|
|
}
|