2020 day 15
This commit is contained in:
parent
ad3c5b35b6
commit
25065ee7b1
20
2020/15/part1and2.js
Normal file
20
2020/15/part1and2.js
Normal 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)
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue