10b
This commit is contained in:
parent
534ddfb2f9
commit
b4ce02882c
|
@ -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
|
|
@ -0,0 +1,10 @@
|
|||
┌┌┐┌S┌┐┌┐┌┐┌┐┌┐┌---┐
|
||||
└|└┘||||||||||||┌--┘
|
||||
┌└-┐└┘└┘||||||└┘└-┐┐
|
||||
┌--┘┌--┐||└┘└┘┐┌┐┌┘-
|
||||
└---┘┌-┘└┘.||-┌┘└┘┘┐
|
||||
|┌|┌-┘┌---┐┌┐-└┐└|┐|
|
||||
|┌┌┘┌┐└┐┌-┘┌┐|┘└---┐
|
||||
┐-└-┘└┐||┌┐|└┐┌-┐┌┐|
|
||||
└.└┐└┌┘|||||┌┘└┐||└┘
|
||||
└┐┘└┘└-┘└┘└┘└--┘└┘.└
|
|
@ -0,0 +1,10 @@
|
|||
.F----7F7F7F7F-7....
|
||||
.|F--7||||||||FJ....
|
||||
.||.FJ||||||||L7....
|
||||
FJL7L7LJLJ||LJ.L-7..
|
||||
L--J.L7...LJS7F-7L7.
|
||||
....F-J..F7FJ|L7L7L7
|
||||
....L7.F7||L7|.L7L7|
|
||||
.....|FJLJ|FJ|F7|.LJ
|
||||
....FJL-7.||.||||...
|
||||
....L---J.LJ.LJLJ...
|
|
@ -0,0 +1,10 @@
|
|||
.┌----┐┌┐┌┐┌┐┌-┐....
|
||||
.|┌--┐||||||||┌┘....
|
||||
.||.┌┘||||||||└┐....
|
||||
┌┘└┐└┐└┘└┘||└┘.└-┐..
|
||||
└--┘.└┐...└┘S┐┌-┐└┐.
|
||||
....┌-┘..┌┐┌┘|└┐└┐└┐
|
||||
....└┐.┌┐||└┐|.└┐└┐|
|
||||
.....|┌┘└┘|┌┘|┌┐|.└┘
|
||||
....┌┘└-┐.||.||||...
|
||||
....└---┘.└┘.└┘└┘...
|
22
ten.py
22
ten.py
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import cv2 as cv
|
||||
|
||||
from useful import *
|
||||
|
||||
bit = {(-1, 0): 8,
|
||||
|
@ -17,10 +19,8 @@ udlr = {'|': 12, # 1<<3 (u) + 1<<2 (d)
|
|||
|
||||
cs = [[udlr[c] for c in l] for l in lines(open(0))]
|
||||
ca = np.pad(np.array(cs, dtype=int), 1)
|
||||
ic(ca)
|
||||
visited = np.zeros(ca.shape, dtype=int)
|
||||
pos = tuple(coord for coord in collapse(np.nonzero(ca == 65535)))
|
||||
ic(pos)
|
||||
pos = next(zip(*np.nonzero(ca == 65535)))
|
||||
|
||||
def sub(a, b):
|
||||
return (a[0] - b[0], a[1] - b[1])
|
||||
|
@ -42,3 +42,19 @@ while True:
|
|||
break
|
||||
pos = sub(pos, goto[0])
|
||||
print(time // 2)
|
||||
|
||||
canvas = np.kron(visited > 0, np.ones((3, 3), dtype='uint8')) # 1 if part of loop...
|
||||
for (y, x), bend in np.ndenumerate(ca):
|
||||
canvas[y*3:y*3+3,x*3:x*3+3] &= np.asarray([[False, bend & 8, False], # ...and part of the bend
|
||||
[bend & 2, True, bend & 1],
|
||||
[False, bend & 4, False]], dtype=bool)
|
||||
mask = np.pad(canvas, (1,1))
|
||||
for color in count(2): # outside: 2, inside: 3
|
||||
try:
|
||||
empty = next(zip(*np.nonzero(canvas == 0)))
|
||||
except StopIteration: # all filled!
|
||||
break
|
||||
cv.floodFill(canvas, mask, empty, color)
|
||||
assert color == 4
|
||||
smallvas = canvas[1::3,1::3]
|
||||
print(len(np.where(smallvas == 3)[0]))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
from functools import cache, reduce
|
||||
from itertools import chain, combinations, cycle, dropwhile, groupby, pairwise, permutations, product, takewhile
|
||||
from itertools import chain, combinations, count, cycle, dropwhile, groupby, pairwise, permutations, product, takewhile
|
||||
from more_itertools import batched, collapse, sliding_window
|
||||
from collections import defaultdict, deque
|
||||
import re, sys
|
||||
|
|
Loading…
Reference in New Issue