and cheated just a little to find out how to skip ahead using coprimes
This commit is contained in:
parent
559d91b9a6
commit
18bccde2f5
@ -72,14 +72,17 @@ func partTwo() {
|
||||
}
|
||||
}
|
||||
|
||||
// walking the list works fine for the small test inputs but takes far too long on the real schedule
|
||||
t := float64(0)
|
||||
offset := buses[0].route
|
||||
for {
|
||||
loop:
|
||||
t = t + buses[0].route
|
||||
t = t + offset
|
||||
offset = 1
|
||||
for i := range buses {
|
||||
if math.Remainder(t+buses[i].offset, buses[i].route) != 0 {
|
||||
goto loop
|
||||
} else {
|
||||
offset = offset * buses[i].route
|
||||
}
|
||||
}
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user