private void btnDay10a_Click(object sender, EventArgs e) { //Day10.Day10a(); Day10Form _form = new Day10Form(); _form.Show(); }
public void RunWork() { #region Step 0 - Initialization stepData = new List <Day12Spot>(); int index = 0; bool stopRunning = false; foreach (char c in initialState) { stepData.Add(new Day12Spot(index, c)); index++; } stepValues.Add(stepData); comparer.Add(new Day12GenerationComparer(stepData)); this.maxX = Math.Max(stepData.Last().X, maxX); currentStep++; #endregion while (currentStep <= totalSteps && !stopRunning) { stepData = new List <Day12Spot>(); List <Day12Spot> previousStep = new List <Day12Spot>(); if (!VeryLargeStepCount) { previousStep = stepValues[Convert.ToInt32(currentStep) - 1]; } else { previousStep = stepValues[0]; } stepData = CompareAll(previousStep); if (VeryLargeStepCount) { stepValues.Clear(); } stepValues.Add(stepData); comparer.Add(new Day12GenerationComparer(stepData)); this.maxX = Math.Max(stepData.Last().X, maxX); currentStep++; stopRunning = CheckForPattern(ref comparer); } long endValue = Tally(stepValues.Last()); if (stopRunning) { endValue = PatternTally(stepValues.Last()); } //MessageBox.Show(endValue.ToString()); StringBuilder sb = new StringBuilder(); int min = 0; int max = 0; if (!VeryLargeStepCount) { foreach (List <Day12Spot> spotList in stepValues) { foreach (Day12Spot spot in spotList) { if (spot.X - 1 < min) { min = spot.X - 1; } } foreach (Day12Spot spot in spotList) { if (spot.X + 2 - min > max) { max = spot.X + 2 - min; } } } foreach (List <Day12Spot> spotList in stepValues) { string line = ""; int prefix = (spotList.First().X - min); if (prefix > 0) { line = line.PadLeft(prefix, '.'); } foreach (Day12Spot spot in spotList) { line += spot.C.ToString(); } line = line.PadRight(max, '.'); line += Environment.NewLine; sb.Append(line); } } Day10Form _frm = new Day10Form(sb.ToString(), endValue, 12); _frm.Show(); }