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-1.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-1.js')
-rw-r--r-- | day13/day13-1.js | 10 |
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) + |