Unable to load image

Advent of Code Day 5, AKA Stacks 101 :marseyinabox:

I actually stayed up to get a semi-decent score for once (being a eurocel for this is suffering). How are you all faring with shifting boxes around?

![](/images/16702184438592093.webp)

26
Jump in the discussion.

No email address required.

this puzzle made me cry a whole lot i spent an hour trying to parse the input then gave up and did it manually

import parse

with open("day5input.txt") as f:
    _, tlm = f.read().split("\n\n")

stacks = [
    list("RSLFQ"),
    list("NZQGPT"),
    list("SMQB"),
    list("TGZJHCBQ"),
    list("PHMBNFS"),
    list("PCQNSLVG"),
    list("WCF"),
    list("QHGZWVPM"),
    list("GZDLCNR")
]

instructions = list(parse.findall("move {:d} from {:d} to {:d}", tlm))

# part 1

for amount, origin, destination in instructions:
    crates = list(stacks[origin-1].pop() for _ in range(amount))
    stacks[destination-1].extend(crates)

for stack in stacks:
    print(stack[-1])

# part 2

stacks = [
    list("RSLFQ"),
    list("NZQGPT"),
    list("SMQB"),
    list("TGZJHCBQ"),
    list("PHMBNFS"),
    list("PCQNSLVG"),
    list("WCF"),
    list("QHGZWVPM"),
    list("GZDLCNR")
]

for amount, origin, destination in instructions:
    crates = list(stacks[origin-1].pop() for _ in range(amount))
    crates.reverse()
    stacks[destination-1].extend(crates)

for stack in stacks:
    print(stack[-1])
Jump in the discussion.

No email address required.



Now playing: Cave Dweller Concert (DKC).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.