Skip to content

Commit f0b6a9e

Browse files
feat(2020-day-13): solution to part 1
1 parent 5dd4d89 commit f0b6a9e

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

2020/day-13/busSchedules.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const testData = {
77
schedule: '7,13,x,x,59,x,31,19'
88
}
99

10-
describe.only('--- Day 13: Shuttle Search ---', () => {
10+
describe('--- Day 13: Shuttle Search ---', () => {
1111
describe('Part 1', () => {
1212
describe('parseSchedule()', () => {
1313
it('cleans up the schedule', () => {

2020/day-13/input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1000067
2+
17,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,439,x,29,x,x,x,x,x,x,x,x,x,x,13,x,x,x,x,x,x,x,x,x,23,x,x,x,x,x,x,x,787,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,19

2020/day-13/solution.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const fs = require('fs')
22
const path = require('path')
33
const filePath = path.join(__dirname, 'input.txt')
4-
const { inputToArray } = require('../../2018/inputParser')
4+
const { linesToArray } = require('../../2018/inputParser')
5+
const { parseSchedule, findNext } = require('./busSchedules')
56

67
fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
78
if (err) throw err
89

9-
initData = inputToArray(initData.trim())
10+
initData = linesToArray(initData.trim())
1011

1112
const resetInput = () => {
1213
// Deep copy to ensure we aren't mutating the original data
@@ -15,8 +16,11 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
1516

1617
const part1 = () => {
1718
const data = resetInput()
18-
console.debug(data)
19-
return 'No answer yet'
19+
const { wait, route } = findNext({
20+
time: data[0],
21+
schedule: parseSchedule(data[1])
22+
})
23+
return route * wait
2024
}
2125

2226
const part2 = () => {

0 commit comments

Comments
 (0)