github.com/cycloss/advent-of-code@v0.0.0-20221210145555-15039b95faa6/2021/day13/day13Strategy.md (about) 1 # Day x Strategy 2 3 ## Parsing 4 5 - On first pass: 6 - find the largest x and y values 7 - when get to break, parse the instructions into struct with axis as string and int as index 8 - On second pass: 9 - init 2d array: array of array of bools with outer of length == largest y and inner length == largest x, filling the whole thing with bools 10 - go through each coordinate and set to true in 2d array 11 12 ## Algorithm 13 14 - for each instruction 15 - if instruction.axis is x 16 - same as y but for columns 17 - if instruction.axis is y 18 - start on the last row 19 - for i = problem.grid.length - 1; i > instruction.index; i-- 20 - reflectedIndex = problem.grid.length - 1 - i 21 - row = problem.grid[i] 22 - reflectedRow = problem.grid[refIndex] 23 - for j = 0; j < row.length; j++ 24 - b = row[j] 25 - if b: 26 - reflectedRow[j] = true 27 - newRows = `List<List<bool>>` = [] 28 - for i = 0; i < instruction.index; i++ 29 - copy row to new rows 30 - set problem.grid to newRows