You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
aoc2020/day13/solve1.go

28 lines
690 B

package day13
import (
"log"
)
func Solve1() {
// Big number to esaier spot smaller numbers
lowestNextDeparture := schedule.Departure * 1000
lowestNextDepartureLine := 0
// Look for next departure times for lines
for _, line := range schedule.Lines {
// Calculate next departure
nextDeparture := schedule.Departure/line*line + line
// Look for lowest departure time
if nextDeparture < lowestNextDeparture {
lowestNextDeparture = nextDeparture
lowestNextDepartureLine = line
}
}
// Calculate next departure id
nextDepartureId := (lowestNextDeparture - schedule.Departure) * lowestNextDepartureLine
log.Printf("2020-12-13.01: Answer: %d\n", nextDepartureId)
}