2020 day 15

This commit is contained in:
tristan 2020-12-15 15:27:33 +00:00
parent ad3c5b35b6
commit 25065ee7b1
2 changed files with 21 additions and 0 deletions

20
2020/15/part1and2.js Normal file
View file

@ -0,0 +1,20 @@
const input = [1,17,0,10,18,11,6];
const find = 30000000;
let saidNums = new Map();
input.slice(0,input.length-1).forEach((n,i) => saidNums.set(n,i));
let lastNum = input[input.length-1];
let i = input.length;
while (i < find) {
let thisNum = 0;
if (saidNums.has(lastNum)) {
thisNum = (i-1) - saidNums.get(lastNum);
}
saidNums.set(lastNum, i-1);
lastNum = thisNum;
i++;
}
console.log(lastNum)

View file

@ -55,3 +55,4 @@ if (advent) {
12. [:star: :star:](https://adventofcode.com/2020/day/12 "see puzzle") 12. [:star: :star:](https://adventofcode.com/2020/day/12 "see puzzle")
13. [:star: :star:](https://adventofcode.com/2020/day/13 "see puzzle") 13. [:star: :star:](https://adventofcode.com/2020/day/13 "see puzzle")
14. [:star: :star:](https://adventofcode.com/2020/day/14 "see puzzle") 14. [:star: :star:](https://adventofcode.com/2020/day/14 "see puzzle")
15. [:star: :star:](https://adventofcode.com/2020/day/15 "see puzzle")