AdventOfCode/2023/day13/part2.py

78 lines
1.3 KiB
Python

import sys
import os
from pprint import pprint
import time
import math
import numpy as np
#21275 too low
#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()
input_f = ''
if len(sys.argv) == 1:
input_f = 'test'
else:
input_f = sys.argv[1]
with open(input_f) as file:
for line in file:
grid.append(list(line.rstrip()))
steps = []
def difference(l,r):
count = 0
for a,b in zip(l,r):
if a != b:
count += 1
return count
def find_sym(grid):
for i in range(len(grid)):
if i != 0:
count = 0
for l,r in zip(reversed(grid[:i]),grid[i:]):
count += difference(l,r)
if count == 1:
return i
return 0
tmp = []
pprint(grid)
result = 0
for i in grid:
if i == []:
t = find_sym(tmp)
if t == 0:
t = find_sym(list(zip(*tmp)))
result += t
else:
result = result + (100*t)
#print(t)
#input()
tmp = []
else:
tmp.append(i)
print(result)