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.

not that bad imo, didn't know if there was a cleaner way to do the double skip once you hit the indices/blank line

import re
pattern=re.compile("[ \[\]]")

metalist={}
cratecount=0
with open("05.txt","r") as lines:
    crates=True
    for line in lines:
        if(line=="\n"): #skip line between crates and movements
            continue
        if(crates):
            for i in range(len(line.rstrip("\n"))):
                if(line[i]=="1"):
                    crates=False #hit crate pile index, skip line and prep for instructions
                    break
                if(not pattern.match(line[i])):
                    index=int((i-1)/4)+1
                    if index not in metalist:
                        metalist[index]=[]
                        cratecount+=1
                    metalist[index].append(line[i])
        else :#order parsing/enacting
            orders=line.rstrip("\n").split(" ")
            count,fromPile,toPile=int(orders[1]),int(orders[3]),int(orders[5])
            metalist[toPile][:0]=metalist[fromPile][0:count[::-1]] #prepend crates
            metalist[fromPile]=metalist[fromPile][count:] #remove prepended crates
for i in range(cratecount):
    print(metalist[i+1][0],end="")

and you drop the [::-1] for the bonus

btw people on /g/ are making 100+MB input tests, fun to benchmark your solution with

Jump in the discussion.

No email address required.



Now playing: Gang-Plank Galleon remix (DKC).mp3

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