From 18bccde2f5cca3ed2abb7d29fae34981811beef9 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 13 Dec 2020 13:00:53 -0500 Subject: [PATCH] and cheated just a little to find out how to skip ahead using coprimes --- 13/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/13/main.go b/13/main.go index 13cfc71..c04d61f 100644 --- a/13/main.go +++ b/13/main.go @@ -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