Created
October 30, 2024 15:19
-
-
Save boppreh/ed35af46ab35f2bf0fb8e4220ca703fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def find_moves(target): | |
stack = deque([(0, 0, "")]) | |
while True: | |
# current: how many X's we currently have. | |
# clipboard: how many X's were copied. | |
# history: sequence of "T", "C" and "P" | |
current, clipboard, history = stack.popleft() | |
if current >= target: | |
return history | |
stack.append((current+1, clipboard, history+"T")) | |
if current != clipboard: | |
stack.append((current, current, history+"C")) | |
stack.append((current+clipboard, clipboard, history+"P")) | |
moves = find_moves(200) | |
print(f'Found solution that takes {len(moves)} seconds: {moves}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment