Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# turn until you get three hexagons changed to get here
H1 = ["AC", "AB", "ACD"]
# turn until you get two hexagons changed to get here
H2 = ["BCF", "ACF", "BF"]
# turn until you get three hexagons changed to get here
H3 = ["CD", "BC", "AB", "AF", "EF", "CDE"]
# this is my status, look at the hexagons to determine which ones are open
status = set("ABDE") # 110110
def shift(h):
return h[1:] + h[:1]
from collections import deque
from copy import deepcopy
def solve(start_status, start_pos):
fringe = deque([[start_status, start_pos, list()]])
for _ in range(1<<16):
status, pos, path = fringe.popleft()
for i in range(len(pos)):
move = pos[i][0]
new_status = set(status)
for hexa in move:
if hexa in new_status:
new_pos = pos[:]
new_pos[i] = shift(pos[i])
new_path = path + [i]
if not new_status:
return new_path
fringe.append([new_status, new_pos, new_path])
raise Exception("Did not find a solution after a lot of lookin'")
print(solve(status, [H1, H2, H3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment