AdventOfCode/2023/day13/part1.py

69 lines
1.4 KiB
Python
Raw Normal View History

2023-12-14 12:50:57 +01:00
import sys
import os
from pprint import pprint
import time
import math
#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 rotate_grid(grid,times):
for i in range(times):
grid = list(zip(*grid[::-1]))
p(grid)
return grid
def find_sym(grid):
mirror = 0
found = False
for c,col in enumerate(grid):
if c+1 < len(col) and not found:
for r,row in enumerate(grid):
if r+1 < len(grid) and not found:
print('testing ' + str(r))
if grid[r] == grid[r+1]:
for c in range(r,-1,-1):
if (r-c)+r+1 < len(grid):
if grid[c] == grid[(r-c)+r+1]:
found = True
mirror = r+1
else:
return None
return mirror
tmp = []
for i in grid:
if i == []:
print('new grid')
pprint(tmp)
print(find_sym(tmp))
tmp = []
else:
tmp.append(i)