Skip to content

Instantly share code, notes, and snippets.

@andreis
Created April 10, 2021 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreis/be765386050b945fd6978797d0047b45 to your computer and use it in GitHub Desktop.
Save andreis/be765386050b945fd6978797d0047b45 to your computer and use it in GitHub Desktop.
# 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_status.remove(hexa)
else:
new_status.add(hexa)
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