diff --git a/src/Year_2016/P8.py b/src/Year_2016/P8.py new file mode 100644 index 0000000..de99af6 --- /dev/null +++ b/src/Year_2016/P8.py @@ -0,0 +1,53 @@ +import numpy as np + +with open("files/test") as f: + instructions = [line for line in f.read().strip().split("\n")] + +print(instructions) + +# grid = np.zeros((6,50), dtype=int) +init_grid = np.zeros((3, 7), dtype=int) + +# initialize grid +print(init_grid) + + +def rect(instruction, grid): + col, row = int(instruction[5:6]), int(instruction[7:]) + # print(col,row) + grid[:row, :col] = 1 + + +rect(instructions[0], init_grid) + +print(init_grid) + + +def rotate_column(instruction, grid): + x, steps = int(instruction[16:17]), int(instruction[21:]) + # print(x, steps) + new_col = np.roll(grid[:, x : x + 1], steps, axis=0) + grid[:, x : x + 1] = new_col + + +rotate_column(instructions[1], init_grid) + +print(init_grid) + + +def rotate_row(instruction, grid): + y, steps = int(instruction[13:14]), int(instruction[18:]) + # print(y, steps) + new_row = np.roll(grid[y : y + 1, :], steps, axis=1) + grid[y : y + 1, :] = new_row + + +rotate_row(instructions[2], init_grid) + +print(init_grid) + +rotate_column(instructions[3], init_grid) + +print(init_grid) + +print(np.sum(init_grid))