Working on 2023-12-13 p1
This commit is contained in:
parent
f78e360886
commit
8544896239
68
2023/day13/part1.py
Normal file
68
2023/day13/part1.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user