From 8049c42fa34e8801381752e9975593c1f728fb04 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Mon, 11 Dec 2023 21:54:29 +0100 Subject: [PATCH] Starting on 2023-12-11 p1 --- 2023/day11/part1.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 2023/day11/part1.py diff --git a/2023/day11/part1.py b/2023/day11/part1.py new file mode 100644 index 0000000..b0e85ca --- /dev/null +++ b/2023/day11/part1.py @@ -0,0 +1,52 @@ +import sys +import os +from pprint import pprint +import time + +#colors +from termcolor import colored + +grid = [] + +def p(x,*args): + for idx,i in enumerate(x): + for jdx,j in enumerate(i): + if j == '#': + print(colored(j,'red'),end='') + #elif (idx,jdx) in steps: + # print(colored(j,'green'),end='') + else: + print(j,end='') + print() + + +with open(sys.argv[1]) as file: + for line in file: + grid.append(list(line.rstrip())) + +steps = [] + +ngrid = [] + +def expand_galaxy(grid): + ngrid=[] + for r,row in enumerate(grid): + if not '#' in row: + tmp = [] + for i in range(len(grid[0])): + tmp.append('.') + ngrid.append(tmp) + ngrid.append(row) + return ngrid + +def rotate_galaxy(grid,times): + for i in range(times): + grid = list(zip(*grid[::-1])) + return grid + +p(grid) +grid = expand_galaxy(grid) +grid = rotate_galaxy(grid,1) +grid = expand_galaxy(grid) +grid = rotate_galaxy(grid,3) +p(grid)