day 17 python tweaks
parent
8c1696fa32
commit
bbc4075137
34
day17/sol.py
34
day17/sol.py
|
@ -10,7 +10,6 @@ rocks = [
|
|||
wall = 0b10000000_10000000_10000000_10000000_10000000
|
||||
|
||||
jets = ">>><<><>><<<>><>>><<<>>><<<><<<>><>><<>>"
|
||||
|
||||
jets = open("input").read().strip()
|
||||
|
||||
|
||||
|
@ -20,10 +19,10 @@ def ceil(n):
|
|||
return n
|
||||
|
||||
def drop(a, r, jets):
|
||||
# start falling
|
||||
h = ceil(a.bit_length()) + 8*3
|
||||
numjets = 0
|
||||
while True:
|
||||
# push left or right
|
||||
j = next(jets)
|
||||
if j == '<':
|
||||
x = (r<<1)
|
||||
|
@ -48,14 +47,28 @@ def drop(a, r, jets):
|
|||
return a, numjets
|
||||
|
||||
def head(a):
|
||||
# technically this isn't sufficient.
|
||||
# you could imagine a stack of overhangs like
|
||||
#
|
||||
# |# #|
|
||||
# |#### #|
|
||||
# |# #|
|
||||
# |# #|
|
||||
# |# ###|
|
||||
# |# #|
|
||||
#
|
||||
# that a rock might be able to navigate through indefinitely,
|
||||
# but our stacks are much messier than that, so no need to worry.
|
||||
#
|
||||
# we could probably just take the top 10 or so rows and call it good.
|
||||
h = ceil(a.bit_length())
|
||||
x = 0
|
||||
while h >= 8 and x < 0x7f:
|
||||
x = 0x80
|
||||
while h >= 8:
|
||||
h -= 8
|
||||
x |= (a>>h)&0xff
|
||||
if x >= 0x7f:
|
||||
return a>>h
|
||||
return 0
|
||||
if x == 0xff:
|
||||
return a>>h
|
||||
return a
|
||||
|
||||
def height(a):
|
||||
return ceil(a.bit_length())//8
|
||||
|
@ -93,14 +106,15 @@ try:
|
|||
#for i in reversed(range(0,a.bit_length(),8)):
|
||||
# print("{:08b}".format((a>>i)&0xff))
|
||||
#print()
|
||||
finally:
|
||||
pass #print(i, j, stopped)
|
||||
except:
|
||||
print(i, j, stopped)
|
||||
raise
|
||||
|
||||
b, old = seen[(i,j,head(a))]
|
||||
sdiff = stopped - old
|
||||
hdiff = height(a) - height(b)
|
||||
|
||||
goal = 1000000000000
|
||||
goal = 10**12
|
||||
rounds, extra = divmod(goal - stopped, sdiff)
|
||||
for _ in range(extra):
|
||||
r = next(rocki)
|
||||
|
|
Loading…
Reference in New Issue