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.

Doing input parsing seemed like a royal pain in the ass for this one so I just manually entered the initial state of the stacks and removed them from the input file.

start = [['V', 'Q', 'W', 'M', 'B', 'N', 'Z', 'C'],
        ['B', 'C', 'W', 'R', 'Z', 'H'],
        ['J', 'Q', 'R', 'F'],
        ['T', 'M', 'N', 'F', 'H', 'W', 'S', 'Z'],
        ['P', 'Q', 'N', 'L', 'W', 'F', 'G'],
        ['W', 'P', 'L'],
        ['J', 'Q', 'C', 'G', 'R', 'D', 'B', 'V'],
        ['W', 'B', 'N', 'Q', 'Z'],
        ['J', 'T', 'G', 'C', 'F', 'L', 'H']]

foo = []
with open('day5_input.txt', 'r') as inp:
    foo = inp.read().split('\n')

for f in foo:
    f = f.split(' ')
    amount = int(f[1])
    source = int(f[3])-1
    dest = int(f[5])-1
    move = start[source][:amount]
    start[source] = start[source][amount:]
    move.reverse() #remove this for part 2
    start[dest] = move + start[dest]

print("".join([i[0] for i in start]))
Jump in the discussion.

No email address required.

Luckily because it's single digit columns with a regular step you could just use absolute indexing. But its not very modular

Jump in the discussion.

No email address required.



Now playing: Voices of the Temple (DKC).mp3

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