summaryrefslogtreecommitdiffstats
path: root/day13/day13-2.js
diff options
context:
space:
mode:
Diffstat (limited to 'day13/day13-2.js')
-rw-r--r--day13/day13-2.js22
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)
+