From a1cb1a1b16b2304ee2c688e289395c65e4d7a657 Mon Sep 17 00:00:00 2001 From: Piotr Russ Date: Sun, 13 Dec 2020 12:27:49 +0100 Subject: day13 --- day13/day13-2.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 day13/day13-2.js (limited to 'day13/day13-2.js') 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) + -- cgit v1.2.3