class Harbor: stacks: List[Stack] def execute(self, i: Instruction): source = self.stacks[i.source] destination = self.stacks[i.destination] payload = source.popsome(i.count) destination.extend(payload) @dataclass class Stack: boxes: List[Box] def popsome(self, count: int) -> List[Box]: tail = self.boxes[-count:] self.boxes = self.boxes[:-count] return tail def extend(self, some: List[Box]): self.boxes.extend(some)