Created
March 6, 2020 10:56
-
-
Save ahmed4end/6a18ecaef7f7a8b6bf9c1413c74396a2 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
board = "RBYYBBRRB" | |
hand = "YRBGB" | |
import re | |
def play(board=list(board+" "), hand=list(hand), trac=[], c=0): | |
try: | |
hand[c] | |
except: | |
trac.append(["".join(board[:-1]), c]) | |
if "".join(board[:-1]) == "": | |
trac.append(["".join(board[:-1]), c]) | |
for f in hand[c:]: | |
for i,j in enumerate(board): | |
board.insert(i, f) | |
move = re.sub(r"([A-Z])\1\1", r"", "".join(board[:-1])) | |
explain = re.sub(r"([A-Z])\1\1", r"[\1\1\1]", "".join(board[:-1])) | |
if len("".join(board[:-1])) != len(move) or len("".join(board[:-1]))<3: | |
auto_remove = re.sub(r"([A-Z])\1{2,}", "", move) | |
if len(move) != len(auto_remove): | |
move = auto_remove | |
play(board=list(move+" "), hand=hand, trac=trac, c=c+1) | |
del board[i] | |
return trac | |
trac = play() | |
shortest_moves = min([i for i in trac if len(i[0])==len(min(trac, key=lambda x:len(x[0]))[0])], key=lambda x: x[1]) | |
print(shortest_moves[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment