From 25065ee7b190f4b091b231bff9e522582bc71e61 Mon Sep 17 00:00:00 2001 From: tristan Date: Tue, 15 Dec 2020 15:27:33 +0000 Subject: [PATCH] 2020 day 15 --- 2020/15/part1and2.js | 20 ++++++++++++++++++++ README.md | 1 + 2 files changed, 21 insertions(+) create mode 100644 2020/15/part1and2.js diff --git a/2020/15/part1and2.js b/2020/15/part1and2.js new file mode 100644 index 0000000..d9777ad --- /dev/null +++ b/2020/15/part1and2.js @@ -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) \ No newline at end of file diff --git a/README.md b/README.md index 5d36b76..512bad4 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,4 @@ if (advent) { 12. [:star: :star:](https://adventofcode.com/2020/day/12 "see puzzle") 13. [:star: :star:](https://adventofcode.com/2020/day/13 "see puzzle") 14. [:star: :star:](https://adventofcode.com/2020/day/14 "see puzzle") +15. [:star: :star:](https://adventofcode.com/2020/day/15 "see puzzle")