This commit is contained in:
Tim Stallard 2017-12-03 16:59:18 +00:00
parent 77d1850bb6
commit 9f0f0a5a6c
Signed by: Tim
GPG Key ID: AAE46381AF6A3FE8
2 changed files with 50 additions and 0 deletions

1
day03/part1.txt Normal file
View File

@ -0,0 +1 @@
I just calculated it manually, I'll probably write some code for it sometime

49
day03/part2.js Normal file
View File

@ -0,0 +1,49 @@
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++;
}