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)
|
t := float64(0)
|
||||||
|
offset := buses[0].route
|
||||||
for {
|
for {
|
||||||
loop:
|
loop:
|
||||||
t = t + buses[0].route
|
t = t + offset
|
||||||
|
offset = 1
|
||||||
for i := range buses {
|
for i := range buses {
|
||||||
if math.Remainder(t+buses[i].offset, buses[i].route) != 0 {
|
if math.Remainder(t+buses[i].offset, buses[i].route) != 0 {
|
||||||
goto loop
|
goto loop
|
||||||
|
} else {
|
||||||
|
offset = offset * buses[i].route
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user