Finished 2023-12-13 p1 & p2

This commit is contained in:
Frederik Baerentsen 2023-12-18 20:22:59 -05:00
parent 7ce86c3d44
commit 48918e0077
3 changed files with 144 additions and 1 deletions

66
2023/day13/part1.1.py Normal file
View File

@ -0,0 +1,66 @@
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 find_sym(grid):
for i in range(len(grid)):
if i != 0:
if all(l == r for l,r in zip(reversed(grid[:i]),grid[i:])):
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)

View File

@ -117,7 +117,7 @@ for i in grid:
if i == []:
t = find_sym(tmp)
print(t)
#input()
input()
if t[0] != None:
if t[1] == 'c':
result += t[0]

77
2023/day13/part2.py Normal file
View File

@ -0,0 +1,77 @@
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)