day 3
This commit is contained in:
parent
77d1850bb6
commit
9f0f0a5a6c
1
day03/part1.txt
Normal file
1
day03/part1.txt
Normal file
@ -0,0 +1 @@
|
||||
I just calculated it manually, I'll probably write some code for it sometime
|
49
day03/part2.js
Normal file
49
day03/part2.js
Normal 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++;
|
||||
}
|
Loading…
Reference in New Issue
Block a user