Skip to content

Instantly share code, notes, and snippets.

@mlazos
Created September 21, 2025 08:17
Show Gist options
  • Select an option

  • Save mlazos/df2e10ec9a424047efb1fb3f98da565f to your computer and use it in GitHub Desktop.

Select an option

Save mlazos/df2e10ec9a424047efb1fb3f98da565f to your computer and use it in GitHub Desktop.
'''
Online Python Interpreter.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
from dataclasses import dataclass
from copy import deepcopy
# blocks
problem1 = ([['A', 'B', 'C'], ['D', 'E']], [['B', 'C', 'A'], ['D', 'E']])
@dataclass
class State:
top_to_stack: dict[str, str]
stacks: list[list]
@staticmethod
def from_problem(problem):
cur_state, _ = problem
cur_state = deepcopy(cur_state)
top_to_stack = {stack[-1] : stack for stack in cur_state}
return State(top_to_stack, cur_state)
def move(self, top_block, dst_top_block):
stack = self.top_to_stack.pop(top_block)
block = stack.pop()
self.top_to_stack[stack[-1]] = stack
if dst_top_block is None:
new_stack = [block]
self.top_to_stack[block] = new_stack
self.stacks.append(new_stack)
else:
dst_stack = self.top_to_stack[dst_top_block]
dst_stack.append(block)
self.top_to_stack.pop(dst_top_block)
self.top_to_stack[block] = dst_stack
def all_moves(self):
srcs = list(self.top_to_stack.keys())
dsts = list(self.top_to_stack.keys()) + [None]
return itertools.product(srcs, dsts)
state = State.from_problem(problem1)
print(state)
state.move("C", "E")
print(state)
def solve_basline(problem):
pass
def solve(prob):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment