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.

Forgot the + in my numbers regex and it fucked with me for nearly an hour. Really should have just put the lists in manually too but that would mean it won.

Part 1:

import re

storage = dict()

with open('input', 'r') as f: 

    line = f.readline()

    while '[' in line:

        ptr = 0

        bucket = 1

        ticker = 0

        for i in range(0, len(line)):

            if line[i] is '[':

                if bucket in storage.keys():

                    storage.get(bucket).insert(0, line[i+1])

                else:

                    thing = [line[i+1]]

                    storage[bucket] = thing

            ticker += 1

            if line[i] is ']':

                ticker = 0

                bucket += 1

            if ticker is 4:

                ticker = 0

                bucket += 1

        line = f.readline()

    line = f.readline()

    while line:

        print(line)

        dat = re.findall('\d+', line)

        if len(dat) < 3:

            line = f.readline()

            continue

        move_from = storage.get(int(dat[1]))

        move_to = storage.get(int(dat[2]))

        total = int(dat[0])

        for thing in range(total):

            item = storage.get(int(dat[1])).pop()

            storage.get(int(dat[2])).append(item)

        line = f.readline()

finstr = ''

for key in sorted(list(storage.keys())):

    finstr += storage.get(key)[-1]

print(finstr)

Part 2:

import re

storage = dict()

with open('input', 'r') as f:

    line = f.readline()

    while '[' in line:

        ptr = 0

        bucket = 1

        ticker = 0

        for i in range(0, len(line)):

            if line[i] is '[':

                if bucket in storage.keys():

                    storage.get(bucket).insert(0, line[i+1])

                else:

                    thing = [line[i+1]]

                    storage[bucket] = thing

            ticker += 1

            if line[i] is ']':

                ticker = 0

                bucket += 1

            if ticker is 4:

                ticker = 0

                bucket += 1

        line = f.readline()

    line = f.readline()

    while line:

        dat = re.findall('\d+', line)

        if len(dat) < 3:

            line = f.readline()

            continue

        move_from = storage.get(int(dat[1]))

        move_to = storage.get(int(dat[2]))

        total = int(dat[0])

        teststr = ''

        items = []

        for thing in range(total):

            items.append(storage.get(int(dat[1])).pop())

        if (len(items) > 1):

            items.reverse()

            storage.get(int(dat[2])).extend(items)

        else:

            storage.get(int(dat[2])).extend(items)

        line = f.readline()

finstr = ''

for key in sorted(list(storage.keys())):

    finstr += storage.get(key)[-1]

print(finstr)
Jump in the discussion.

No email address required.

Impressive. Normally people with such severe developmental disabilities struggle to write much more than a sentence or two. He really has exceded our expectations for the writing portion. Sadly the coherency of his writing, along with his abilities in the social skills and reading portions, are far behind his peers with similar disabilities.

Jump in the discussion.

No email address required.

:marseysad:

Jump in the discussion.

No email address required.

I put [1-9]+ in my regex instead of [0-9]+ because I'm an idiot, and it threw me off for a good 10 minutes.

Jump in the discussion.

No email address required.

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