You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.0 KiB
Python

4 years ago
"""Solution to 2020/23"""
from collections import deque
EXAMPLE = '389125467'
INPUT = '952316487'
# INPUT = EXAMPLE
MOVES = 100
def main():
all_cups = deque(sorted(INPUT))
cups = deque(INPUT)
for move in range(MOVES):
print(f'-- MOVE {move + 1} --')
while all_cups[0] != cups[0]:
all_cups.rotate()
print(f'cups: {list(cups)}')
cur = cups[0]
cups.rotate(-1)
lift = [cups.popleft(), cups.popleft(), cups.popleft()]
next_cup = cups[0]
print('pick up:', lift)
all_cups.rotate()
while all_cups[0] in lift:
all_cups.rotate()
destination = all_cups[0]
print('destination:', destination)
while cups[-1] != destination:
cups.rotate()
cups.extend(lift)
while cups[0] != next_cup:
cups.rotate()
print('-- Final:--')
print(cups)
print()
while cups[0] != '1':
cups.rotate()
cups.popleft()
print(''.join(list(cups)))
main()