diff options
author | 2020-12-13 12:27:49 +0100 | |
---|---|---|
committer | 2020-12-13 12:27:49 +0100 | |
commit | a1cb1a1b16b2304ee2c688e289395c65e4d7a657 (patch) | |
tree | 9b2fbe623d6a15837c084bc949d03b1d90d8efb9 /day13/day13-2.js | |
parent | 21b42b5a3910c3efb670660fbf417a832ec0a238 (diff) | |
download | advent_of_code_2020-a1cb1a1b16b2304ee2c688e289395c65e4d7a657.tar.gz advent_of_code_2020-a1cb1a1b16b2304ee2c688e289395c65e4d7a657.tar.bz2 advent_of_code_2020-a1cb1a1b16b2304ee2c688e289395c65e4d7a657.zip |
day13
Diffstat (limited to 'day13/day13-2.js')
-rw-r--r-- | day13/day13-2.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/day13/day13-2.js b/day13/day13-2.js new file mode 100644 index 0000000..0e6d11c --- /dev/null +++ b/day13/day13-2.js @@ -0,0 +1,22 @@ +const data = require('./data') +const [first, ...busses] = data + .split('\n') + .filter(d => d !== '')[1] + .split(',') + .map(d => d === 'x' ? null : parseInt(d)) + +let interval = first, t = 0 +busses.forEach((b, i) => { + if (b) { + while(true){ + if ((t+i+1) % b === 0) { + interval *= b + break + } + t += interval + } + } +}) + +console.log('Answer: ', t) + |