summaryrefslogtreecommitdiffstats
path: root/day13/day13-1.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-12-13 12:27:49 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-12-13 12:27:49 +0100
commita1cb1a1b16b2304ee2c688e289395c65e4d7a657 (patch)
tree9b2fbe623d6a15837c084bc949d03b1d90d8efb9 /day13/day13-1.js
parent21b42b5a3910c3efb670660fbf417a832ec0a238 (diff)
downloadadvent_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-1.js')
-rw-r--r--day13/day13-1.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/day13/day13-1.js b/day13/day13-1.js
new file mode 100644
index 0000000..16458cd
--- /dev/null
+++ b/day13/day13-1.js
@@ -0,0 +1,10 @@
+const data = require('./data')
+const dataLines = data.split(/\n/g).filter(d => d)
+const currentTime = parseInt(dataLines[0])
+const busses = dataLines[1].split(',').filter(d => d !== 'x').map(d => parseInt(d))
+const timetable = busses
+ .map(b => ({'bus': b, 'time': b - currentTime % b}))
+ .sort((a,b) => a.time - b.time)
+
+console.log('Answer: ', timetable[0].bus * timetable[0].time)
+