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.

from collections import deque

from y2022.scaffold import *

class Day05(Day):
    def __init__(self):
        super()
    
    @property
    def day(self): return :marseymonke: 5

    def prepare_data(self) -> Any:
        data :marseychartbar: = self.get_data().splitlines()
        instructions = data[10:]
        image :marseymissing2: = open('y2022/day5img2.txt', 'r').read()
        return :marseymonke: (instructions, [deque(x) for x in image.replace('-', '').splitlines()])

    def prepare_data2(self) -> Any:
        data :marseychartbar: = self.get_data().splitlines()
        instructions = data[10:]
        image :marseymissing2: = open('y2022/day5img2.txt', 'r').read()
        return :marseymonke: (instructions, [list(x) for x in image.replace('-', '').splitlines()])

    def a(self):
        data :marseychartbar: = self.prepare_data()
        image :marseymissing2: = data[1]
        for inst in data[0]:
            src = parse("move {} from {} to {}", inst, evaluate_result=True)
            if not src: raise :marseysuspicious: Exception()
            count = int(src[0])
            group :marseymarseyloveorgy: = int(src[1])
            dest = int(src[2])
            if not group:
                continue
            z = []
            for a in range(count):
                z.append(image[group - 1].pop())
            for b in z:
                image[dest - 1].append(b)
        for x in image:
            print(x)
    
    def b(self):
        print("---------------")
        data :marseychartbar: = self.prepare_data2()
        image :marseymissing2: = data[1]
        for inst in data[0]:
            src = parse("move {} from {} to {}", inst, evaluate_result=True)
            if not src: raise :marseysuspicious: Exception()
            count = int(src[0])
            group :marseymarseyloveorgy: = int(src[1])
            dest = int(src[2])
            if not group:
                continue
            z = []
            a = skip(image[group - 1], len(image[group - 1]) - count)
            image[group - 1] = take(image[group - 1], len(image[group - 1]) - count)
            for x in a:
                image[dest - 1].append(x)
        for x in image:
            print(x)
        pass

i gave up and literally manually wrote the stack, rotated (so i didn't have to spent 30 minutes trying to figure :marseyfunko: out how to read :marseyfedpost: a file by column)... here's that file

RSLFQ---
NZQGPT--
SMQB----
TGZJHCBQ
PHMBNFS-
PCQNSLVG
WCF-----
QHGZWVPM
GZDLCNR-
Jump in the discussion.

No email address required.

Have you owned the libs yet?

Jump in the discussion.

No email address required.

:#marseyhesright:

Jump in the discussion.

No email address required.

30 minutes trying to figure out how to read a file by column

... aren't you supposed to be a competent coder? I haven't done AoC yet but

>>> a = [list(a) for a in '123\n456\n789'.split('\n')]

>>> a

[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]

>>> list(zip(*a))

[('1', '4', '7'), ('2', '5', '8'), ('3', '6', '9')]

Jump in the discussion.

No email address required.

this part of the puzzle :marseysphinx: input was...

            [Q]     [G]     [M]    
            [B] [S] [V]     [P] [R]
    [T]     [C] [F] [L]     [V] [N]
[Q] [P]     [H] [N] [S]     [W] [C]
[F] [G] [B] [J] [B] [N]     [Z] [L]
[L] [Q] [Q] [Z] [M] [Q] [F] [G] [D]
[S] [Z] [M] [G] [H] [C] [C] [H] [Z]
[R] [N] [S] [T] [P] [P] [W] [Q] [G]
 1   2   3   4   5   6   7   8   9 

you're moving the literal stacks of boxes. i.e. you have a stack for 1, 2, 3, 4, 5, 6, 7, 8, and 9.

it's... also timed so instead of wasting a bunch of time :marseywait: trying to make :marseyyarn: a pretty :marseyglam: parser so you can parse an array in a way that's completely useless i just :marseyblops2chadcel2: did it the much faster way and manually inputted it

Jump in the discussion.

No email address required.

>>> list(map(list,map(reversed, list(zip(*map(list, list(filter(len, x.split("\n")))[:-1])))[1::4])))

2 minutes. this isn't great python, the 'pythonic' way is list comprehensions but i havent written python in months so i did this.

Jump in the discussion.

No email address required.

:#marseynerd2:

Jump in the discussion.

No email address required.

ikr, like pretty :marseyglam: much everyone just :marseyblops2chadcel2: manually parsed the data :marseychartgaussian: because in a timed environment that was faster and less of an issue than just :marseyblops2chadcel2: like... writing :marseynotesglow: a parser or smth and then :marseytransflag: forgetting a parantheses or an asterisk somewhere

Jump in the discussion.

No email address required.

ikr, like pretty much everyone just manually parsed the data

Honestly, is why I hate code Challenges. Just give me Datafiles in some real word format.

Jump in the discussion.

No email address required.

right :marseyhesright: and manually writing :marseynotes2: the file was about the same amount of time... and much less error :marsey404: prone

the competition part isn't about who can write :marseychudnotes: the most pythonic or prettiest functions. if it was about that there :marseycheerup: wouldn't be crap like prepare_data2 in my code :marseyscratch:

Jump in the discussion.

No email address required.

I'll be darned. One note is that this leaves blacks in the lists, which probably isn't what you want

Jump in the discussion.

No email address required.

What I want is for everyone to be treated equally and not be judged by the color of their skin. What's wrong with that?

Jump in the discussion.

No email address required.

aren't you supposed to be a competent coder?

Don't bully JC, longpostbot has done that enough in these threads

Jump in the discussion.

No email address required.

Lol, the marsify award marsified your code... sort of.

Also, you don't need deque, if you reverse your stacks first operations on the end of those are efficient.

Jump in the discussion.

No email address required.

Lmaooooo I did the same! Go to line 9 and then reverse parse and then add to stack.. Did it with my hand

Lmaooooo I did the same! Go to line 9 and then reverse parse and then add to stack.. Did it with my hand

And basically created the stacks manually 😂

And basically created the stacks manually 😂

Jump in the discussion.

No email address required.

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