Working on 2023-12-10 p2

This commit is contained in:
FrederikBaerentsen 2023-12-11 20:36:17 +01:00
parent a85d9d65ea
commit 329e2d62b1
4 changed files with 57 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import sys import sys
import os
from pprint import pprint from pprint import pprint
import time
#colors #colors
from termcolor import colored from termcolor import colored
@ -81,6 +83,9 @@ while not found:
#print('Start: ' + str(cur) + ' ' + wall(cur)) #print('Start: ' + str(cur) + ' ' + wall(cur))
dirc = '' dirc = ''
if len(sys.argv) == 3:
p(grid,steps)
time.sleep(float(sys.argv[2]))
#print('Trying to find way') #print('Trying to find way')
#print('Previous is ' + str(prev) + wall(prev)) #print('Previous is ' + str(prev) + wall(prev))

View File

@ -1,22 +1,32 @@
import sys import sys
import os
from pprint import pprint from pprint import pprint
import time
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
#colors #colors
from termcolor import colored from termcolor import colored
grid = [] grid = []
cur = []
log = True log = True
def p(x,steps): def p(x,steps,inside,*cur):
global log global log
if log: if log:
for idx,i in enumerate(x): for idx,i in enumerate(x):
for jdx,j in enumerate(i): 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='') print(colored(j,'red'),end='')
elif (idx,jdx) in steps: elif (idx,jdx) in steps:
print(colored(j,'green'),end='') print(colored(j,'green'),end='')
elif (idx,jdx) in inside:
print(colored(j,'yellow'),end='')
else: else:
print(j,end='') print(j,end='')
print() print()
@ -33,12 +43,12 @@ with open(sys.argv[1]) as file:
grid.append(line.rstrip()) grid.append(line.rstrip())
for ldx,line in enumerate(grid): for ldx,line in enumerate(grid):
grid[ldx] = line.translate(str.maketrans("-|F7LJ.", "─│┌┐└┘ ")) grid[ldx] = line.translate(str.maketrans("-|F7LJ.", "─│┌┐└┘."))
steps = [] steps = []
inside = []
#p(grid,steps) #p(grid,steps)
found = False found = False
@ -71,7 +81,7 @@ print((y,x-1))
print('Down is ' + wall((y,x+1)) + grid[x+1][y],end='') print('Down is ' + wall((y,x+1)) + grid[x+1][y],end='')
print((y,x+1)) print((y,x+1))
print() print()
p(grid,steps) p(grid,steps,inside)
while not found: while not found:
y = cur[0] y = cur[0]
@ -81,6 +91,9 @@ while not found:
#print('Start: ' + str(cur) + ' ' + wall(cur)) #print('Start: ' + str(cur) + ' ' + wall(cur))
dirc = '' dirc = ''
if len(sys.argv) == 3:
p(grid,steps,inside)
time.sleep(float(sys.argv[2]))
#print('Trying to find way') #print('Trying to find way')
#print('Previous is ' + str(prev) + wall(prev)) #print('Previous is ' + str(prev) + wall(prev))
@ -169,6 +182,18 @@ while not found:
#input() #input()
count += 1 count += 1
#print(cur, start) #print(cur, start)
p(grid,steps) p(grid,steps,inside)
print(count) print(count)
print(count/2) 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))

10
2023/day10/t2.3.1 Normal file
View File

@ -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

10
2023/day10/t2.4 Normal file
View File

@ -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