From 329e2d62b1e24137a521d9a02e6044b48f962d49 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Mon, 11 Dec 2023 20:36:17 +0100 Subject: [PATCH] Working on 2023-12-10 p2 --- 2023/day10/part1.py | 5 +++++ 2023/day10/part2.py | 39 ++++++++++++++++++++++++++++++++------- 2023/day10/t2.3.1 | 10 ++++++++++ 2023/day10/t2.4 | 10 ++++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 2023/day10/t2.3.1 create mode 100644 2023/day10/t2.4 diff --git a/2023/day10/part1.py b/2023/day10/part1.py index afc3c6a..1e37edb 100644 --- a/2023/day10/part1.py +++ b/2023/day10/part1.py @@ -1,5 +1,7 @@ import sys +import os from pprint import pprint +import time #colors from termcolor import colored @@ -81,6 +83,9 @@ while not found: #print('Start: ' + str(cur) + ' ' + wall(cur)) dirc = '' + if len(sys.argv) == 3: + p(grid,steps) + time.sleep(float(sys.argv[2])) #print('Trying to find way') #print('Previous is ' + str(prev) + wall(prev)) diff --git a/2023/day10/part2.py b/2023/day10/part2.py index afc3c6a..2f66e84 100644 --- a/2023/day10/part2.py +++ b/2023/day10/part2.py @@ -1,22 +1,32 @@ import sys +import os from pprint import pprint +import time + +from shapely.geometry import Point +from shapely.geometry.polygon import Polygon #colors from termcolor import colored grid = [] - +cur = [] log = True -def p(x,steps): +def p(x,steps,inside,*cur): global log if log: for idx,i in enumerate(x): for jdx,j in enumerate(i): - if j == 'S': + if len(cur) < 0: + if cur[1] == idx and cur[0] == jdx: + print(colored(j,'blue'),end='') + elif j == 'S': print(colored(j,'red'),end='') elif (idx,jdx) in steps: print(colored(j,'green'),end='') + elif (idx,jdx) in inside: + print(colored(j,'yellow'),end='') else: print(j,end='') print() @@ -33,12 +43,12 @@ with open(sys.argv[1]) as file: grid.append(line.rstrip()) for ldx,line in enumerate(grid): - grid[ldx] = line.translate(str.maketrans("-|F7LJ.", "─│┌┐└┘ ")) + grid[ldx] = line.translate(str.maketrans("-|F7LJ.", "─│┌┐└┘.")) steps = [] - +inside = [] #p(grid,steps) found = False @@ -71,7 +81,7 @@ print((y,x-1)) print('Down is ' + wall((y,x+1)) + grid[x+1][y],end='') print((y,x+1)) print() -p(grid,steps) +p(grid,steps,inside) while not found: y = cur[0] @@ -81,6 +91,9 @@ while not found: #print('Start: ' + str(cur) + ' ' + wall(cur)) dirc = '' + if len(sys.argv) == 3: + p(grid,steps,inside) + time.sleep(float(sys.argv[2])) #print('Trying to find way') #print('Previous is ' + str(prev) + wall(prev)) @@ -169,6 +182,18 @@ while not found: #input() count += 1 #print(cur, start) -p(grid,steps) +p(grid,steps,inside) print(count) print(count/2) +polygon = Polygon(steps) + +for ydx,y in enumerate(grid): + for xdx,x in enumerate(y): + if polygon.contains(Point(ydx,xdx)): + inside.append((ydx,xdx)) + if len(sys.argv) == 4: + p(grid,steps,inside,xdx,ydx) + time.sleep(float(sys.argv[3])) +if len(sys.argv) == 2: + p(grid,steps,inside) +print(len(inside)) diff --git a/2023/day10/t2.3.1 b/2023/day10/t2.3.1 new file mode 100644 index 0000000..8f950ae --- /dev/null +++ b/2023/day10/t2.3.1 @@ -0,0 +1,10 @@ +FF7FSF7F7F7F7F7F---7 +L|LJ||||||||||||F--J +FL-7LJLJ||||||LJL-77 +F--JF--7||LJLJ7F7FJ- +L---JF-JLJ.||-FJLJJ7 +|F|F-JF---7F7-L7L|7| +|FFJF7L7F-JF7|JL---7 +7-L-JL7||F7|L7F-7F7| +L.L7LFJ|||||FJL7||LJ +L7JLJL-JLJLJL--JLJ.L diff --git a/2023/day10/t2.4 b/2023/day10/t2.4 new file mode 100644 index 0000000..97d940f --- /dev/null +++ b/2023/day10/t2.4 @@ -0,0 +1,10 @@ +FF7F┼F7F7F7F7F7F---7 +L|LJ||||||||||||F--J +FL-7LJLJ|S||||LJL-77 +F--JF--7||LJLJ7F7FJ- +L---JF-JFJ.||-FJLJJ7 +|F|F-JF---7F7-L7L|7| +|FFJF7L7F-JF7|JL---7 +7-L-JL7||F7|L7F-7F7| +L.L7LFJ|||||FJL7||LJ +L7JLJL-JLJLJL--JLJ.L