From 48918e0077dc7267cd8ccd0e4222a81f19b9da90 Mon Sep 17 00:00:00 2001 From: Frederik Baerentsen Date: Mon, 18 Dec 2023 20:22:59 -0500 Subject: [PATCH] Finished 2023-12-13 p1 & p2 --- 2023/day13/part1.1.py | 66 +++++++++++++++++++++++++++++++++++++ 2023/day13/part1.py | 2 +- 2023/day13/part2.py | 77 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 2023/day13/part1.1.py create mode 100644 2023/day13/part2.py diff --git a/2023/day13/part1.1.py b/2023/day13/part1.1.py new file mode 100644 index 0000000..c31423f --- /dev/null +++ b/2023/day13/part1.1.py @@ -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) diff --git a/2023/day13/part1.py b/2023/day13/part1.py index 0d75246..7dc43ab 100644 --- a/2023/day13/part1.py +++ b/2023/day13/part1.py @@ -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] diff --git a/2023/day13/part2.py b/2023/day13/part2.py new file mode 100644 index 0000000..f57f3db --- /dev/null +++ b/2023/day13/part2.py @@ -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)