day 1 from desktop

This commit is contained in:
Tim Stallard 2018-12-02 18:18:10 +00:00
parent dc0f15fe6e
commit 1a085be4db
3 changed files with 1035 additions and 0 deletions

1016
01/input.txt Normal file

File diff suppressed because it is too large Load Diff

3
01/part1.js Normal file
View File

@ -0,0 +1,3 @@
var input = require("fs").readFileSync("input.txt").toString();
var nums = input.split("\n").filter(a=>(a)).map(a=>(parseInt(a)));
console.log(nums.reduce((a,b)=>(a+b)));

16
01/part2.js Normal file
View File

@ -0,0 +1,16 @@
var input = require("fs").readFileSync("input.txt").toString();
var nums = input.split("\n").filter(a=>(a)).map(a=>(parseInt(a)));
var seen = {};
var total = 0;
while(true){
for(var i of nums){
total += i;
if(!seen[total]){
seen[total]=1;
}
else{
console.log(total);
return 0;
}
}
}