day 17 python refactor
parent
40b9f86f4c
commit
db649d4a56
41
day17/sol.py
41
day17/sol.py
|
@ -16,27 +16,13 @@ a = 0b11111111
|
|||
wall = 0b10000000_10000000_10000000_10000000_10000000
|
||||
stopped = 0
|
||||
r = 0
|
||||
while stopped < 2022:
|
||||
if r == 0:
|
||||
|
||||
def drop(a, r, jets):
|
||||
# start falling
|
||||
r = next(rocki)
|
||||
h = a.bit_length() + 8*3
|
||||
if h % 8 != 0:
|
||||
h += 8 - h%8
|
||||
#for i in reversed(range(0,a.bit_length(),8)):
|
||||
# print("{:08b}".format((a>>i)&0xff))
|
||||
#print()
|
||||
else:
|
||||
# continue falling?
|
||||
if r & (a>>(h-8)) == 0:
|
||||
h -= 8
|
||||
else:
|
||||
# stop
|
||||
a |= (r<<h)
|
||||
r = 0
|
||||
stopped += 1
|
||||
continue
|
||||
|
||||
while True:
|
||||
j = next(jets)
|
||||
if j == '<':
|
||||
x = (r<<1)
|
||||
|
@ -50,5 +36,26 @@ while stopped < 2022:
|
|||
if x & (a>>h) == 0:
|
||||
r = x
|
||||
|
||||
# continue falling?
|
||||
if r & (a>>(h-8)) == 0:
|
||||
h -= 8
|
||||
assert h > 0
|
||||
else:
|
||||
# stop
|
||||
a |= (r<<h)
|
||||
return a
|
||||
|
||||
|
||||
a = 0b11111111
|
||||
wall = 0b10000000_10000000_10000000_10000000_10000000
|
||||
stopped = 0
|
||||
while stopped < 2022:
|
||||
r = next(rocki)
|
||||
a = drop(a,r,jets)
|
||||
stopped += 1
|
||||
#for i in reversed(range(0,a.bit_length(),8)):
|
||||
# print("{:08b}".format((a>>i)&0xff))
|
||||
#print()
|
||||
|
||||
import math
|
||||
print(math.ceil((a>>8).bit_length()/8))
|
||||
|
|
Loading…
Reference in New Issue