|
|
|
@ -52,8 +52,8 @@ def line():
@@ -52,8 +52,8 @@ def line():
|
|
|
|
|
settled = True |
|
|
|
|
rock = [(NY, NX), (NY, NX + 1), (NY, NX + 2), (NY, NX + 3)] |
|
|
|
|
chamber.addRock(rock) |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 1, chamber.topEdge() - 1)) |
|
|
|
|
chamber.removeEmpty() |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 1, chamber.topEdge() - 1)) |
|
|
|
|
|
|
|
|
|
def cross(): |
|
|
|
|
relativeX = 0 |
|
|
|
@ -80,8 +80,8 @@ def cross():
@@ -80,8 +80,8 @@ def cross():
|
|
|
|
|
settled = True |
|
|
|
|
rock = [(NY, NX), (NY + 1, NX - 1), (NY + 1, NX), (NY + 1, NX + 1), (NY + 2, NX)] |
|
|
|
|
chamber.addRock(rock) |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 2, chamber.topEdge() - 1)) |
|
|
|
|
chamber.removeEmpty() |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 2, chamber.topEdge() - 1)) |
|
|
|
|
|
|
|
|
|
def l(): |
|
|
|
|
relativeX = 0 |
|
|
|
@ -108,8 +108,8 @@ def l():
@@ -108,8 +108,8 @@ def l():
|
|
|
|
|
settled = True |
|
|
|
|
rock = [(NY, NX), (NY, NX + 1), (NY, NX + 2), (NY + 1, NX + 2), (NY + 2, NX + 2)] |
|
|
|
|
chamber.addRock(rock) |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 3, chamber.topEdge() - 1)) |
|
|
|
|
chamber.removeEmpty() |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 3, chamber.topEdge() - 1)) |
|
|
|
|
|
|
|
|
|
def staff(): |
|
|
|
|
relativeX = 0 |
|
|
|
@ -136,8 +136,8 @@ def staff():
@@ -136,8 +136,8 @@ def staff():
|
|
|
|
|
settled = True |
|
|
|
|
rock = [(NY, NX), (NY + 1, NX), (NY + 2, NX), (NY + 3, NX)] |
|
|
|
|
chamber.addRock(rock) |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 4, chamber.topEdge() - 1)) |
|
|
|
|
chamber.removeEmpty() |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 4, chamber.topEdge() - 1)) |
|
|
|
|
|
|
|
|
|
def square(): |
|
|
|
|
relativeX = 0 |
|
|
|
@ -164,8 +164,8 @@ def square():
@@ -164,8 +164,8 @@ def square():
|
|
|
|
|
settled = True |
|
|
|
|
rock = [(NY, NX), (NY + 1, NX), (NY + 1, NX + 1), (NY, NX + 1)] |
|
|
|
|
chamber.addRock(rock) |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 5, chamber.topEdge() - 1)) |
|
|
|
|
chamber.removeEmpty() |
|
|
|
|
rockSequence.append(((relativeY, relativeX), 5, chamber.topEdge() - 1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#miscelanious |
|
|
|
@ -184,7 +184,32 @@ def _counter():
@@ -184,7 +184,32 @@ def _counter():
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findCycle() |
|
|
|
|
def cycleFinder(): |
|
|
|
|
global cycleFound |
|
|
|
|
global counter |
|
|
|
|
global skippedValue |
|
|
|
|
if cycleFound: |
|
|
|
|
return |
|
|
|
|
position1, _, _ = rockSequence[-1] |
|
|
|
|
position2, _, _ = rockSequence[-2] |
|
|
|
|
position3, _, _ = rockSequence[-3] |
|
|
|
|
position4, _, _ = rockSequence[-4] |
|
|
|
|
position5, _, _ = rockSequence[-5] |
|
|
|
|
position6, _, _ = rockSequence[-6] |
|
|
|
|
position7, _, _ = rockSequence[-7] |
|
|
|
|
cycle[(position1, position2, position3, position4, position5, position6, position7)] = cycle.get((position1, position2, position3, position4, position5, position6, position7), 0) + len(rockSequence) |
|
|
|
|
if cycle[(position1, position2, position3, position4, position5, position6, position7)] > len(rockSequence): |
|
|
|
|
endOfCycle = rockSequence[-5] |
|
|
|
|
index = cycle[(position1, position2, position3, position4, position5, position6, position7)] - len(rockSequence) |
|
|
|
|
startOfCycle = rockSequence[index - 5] |
|
|
|
|
cycleFound = True |
|
|
|
|
cycleLength = len(rockSequence) - index |
|
|
|
|
cycleValue = endOfCycle[2] - startOfCycle[2] |
|
|
|
|
print('found cycle') |
|
|
|
|
n, rest = divmod(end - len(rockSequence), cycleLength) |
|
|
|
|
counter = len(rockSequence) + cycleLength * n |
|
|
|
|
skippedValue = cycleValue * n |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Building Input, defioning variables |
|
|
|
|
with open('input17.txt','r') as f: |
|
|
|
@ -197,6 +222,8 @@ jetPosition = 0
@@ -197,6 +222,8 @@ jetPosition = 0
|
|
|
|
|
counter = 0 |
|
|
|
|
end = 1000000000000 |
|
|
|
|
rockSequence = [] |
|
|
|
|
cycle = {} |
|
|
|
|
cycleFound = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Main function |
|
|
|
@ -216,7 +243,11 @@ while True:
@@ -216,7 +243,11 @@ while True:
|
|
|
|
|
square() |
|
|
|
|
if _counter(): |
|
|
|
|
break |
|
|
|
|
if counter == 5: |
|
|
|
|
pass |
|
|
|
|
else: |
|
|
|
|
cycleFinder() |
|
|
|
|
if counter % 10000 == 0: |
|
|
|
|
print(counter, 'of', end) |
|
|
|
|
|
|
|
|
|
print(chamber.topEdge() - 1) |
|
|
|
|
print(chamber.topEdge() - 1 + skippedValue) |