adventofcode-2017/day03/part2.js
2017-12-03 16:59:18 +00:00

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++;
}