public int TransformArtAndCountPizelsTurnedOn(string filePath, int iterations) { Dictionary <string, string> rules = CreateRules(filePath); PixelProgram pixelProgram = new PixelProgram(Start); int counter = 0; do { pixelProgram = ExplodePixelProgram(pixelProgram, rules); counter++; } while (counter < iterations); return(pixelProgram.PixelsTurnedOn()); }
public PixelProgram ExplodePixelProgram(PixelProgram current, Dictionary <string, string> rules) { List <string> explodedProgramInput = new List <string>(); int totalNumRows = (current.Size() % 2) == 0 ? current.Size() + 1 : current.Size(); int localNumRows = (current.Size() % 2) == 0 ? 3 : 4; int currentRow = 0; List <List <PixelProgram> > split = current.Split(); foreach (List <PixelProgram> rowOfPrograms in split) { for (int x = 0; x < localNumRows; x++) { explodedProgramInput.Add(""); } foreach (PixelProgram prog in rowOfPrograms) { string mod = ""; List <string> permutations = prog.AllRotationsAndFlips(); foreach (string permutation in permutations) { if (rules.ContainsKey(permutation)) { mod = rules[permutation]; } } if (mod == "") { throw new ArgumentException("Not found in rules"); } string[] modSplit = mod.Split('/'); for (int y = 0; y < localNumRows; y++) { explodedProgramInput[currentRow + y] += modSplit[y]; } } currentRow += localNumRows; } // Now combine them string combined = string.Join("/", explodedProgramInput.ToArray()); return(new PixelProgram(combined)); }