and cheated just a little to find out how to skip ahead using coprimes

This commit is contained in:
David 2020-12-13 13:00:53 -05:00
parent 559d91b9a6
commit 18bccde2f5
1 changed files with 5 additions and 2 deletions

View File

@ -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