From 6137dd6aa44dcce8f1a8ae0c5959ab7d4a6e24eb Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 12 Dec 2018 01:48:50 -0500 Subject: Solve day 12 part 2 --- 2018/day12.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/2018/day12.c b/2018/day12.c index 5f2f04e..d71e592 100644 --- a/2018/day12.c +++ b/2018/day12.c @@ -3,8 +3,9 @@ #include typedef unsigned uint; +typedef unsigned long ulong; -enum { Zero = 128, Len = Zero * 2 }; +enum { Zero = 256, Len = Zero * 2 }; struct State { char pots[Len]; }; @@ -29,7 +30,16 @@ int main() { rulen++; } - for (uint g = 0; g < 20; ++g) { + ulong g; + for (g = 0; g < 50000000000L; ++g) { + if (g == 20) { + int sum = 0; + for (int i = 0; i < Len; ++i) { + if (state.pots[i] == '#') sum += i - Zero; + } + printf("%d\n", sum); + } + struct State next; memset(next.pots, '.', Len); for (uint i = 2; i < Len - 2; ++i) { @@ -39,12 +49,15 @@ int main() { break; } } + if (next.pots[2] == '#' || next.pots[Len - 3] == '#') abort(); + + if (!memcmp(&next.pots[1], state.pots, Len - 1)) break; state = next; } - int sum = 0; - for (int i = 0; i < Len; ++i) { - if (state.pots[i] == '#') sum += i - Zero; + long sum = 0; + for (long i = 0; i < Len; ++i) { + if (state.pots[i] == '#') sum += (50000000000L - g) + i - Zero; } - printf("%d\n", sum); + printf("%ld\n", sum); } -- cgit 1.4.1