internal Lanternfish AgeOneDay() { i--; if (i < 0) { i = 6;//Reset age //spawn new fish Lanternfish spawn = new Lanternfish(8); return(spawn); } return(null); }
public override string Part1(List <string> input, bool isTestRun) { List <Lanternfish> fishes = ReadInput(input); for (int i = 1; i <= 80; i++) { List <Lanternfish> children = new List <Lanternfish>(); //todo single line foreach foreach (Lanternfish lanternfish in fishes) { Lanternfish child = lanternfish.AgeOneDay(); if (child != null) { children.Add(child); } } fishes.AddRange(children); //Console.WriteLine($"Aged {i} | {string.Join(',', fishes.Select(f => f.Age))}"); } return($"{fishes.Count()}"); }