static int B(string[] input) { const int MAX_GENERATION = 1_000_000_000; Dictionary <int, int> seenValues = new Dictionary <int, int>(); var area = CollectionArea.FromInput(input); while (area.Generation < MAX_GENERATION) { area.Step(); if (area.Generation > 1000) { if (seenValues.ContainsKey(area.Value())) { var gen = area.Generation; var prevGen = seenValues[area.Value()]; var gendiff = gen - prevGen; var skipSteps = (MAX_GENERATION - area.Generation) / gendiff; area.SkipForward(skipSteps * gendiff); } else { seenValues[area.Value()] = area.Generation; } } } return(area.Value()); }
static int A(string[] input, bool debug = false) { var area = CollectionArea.FromInput(input); if (debug) { Console.WriteLine(area.ToString()); } for (int i = 0; i < 10; i++) { area.Step(); if (debug) { Console.WriteLine(area.ToString()); } } return(area.Value()); }