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

View File

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

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