Advent of Code 2022 Day 5 Walk-Through

preview_player
Показать описание

Please attempt the problem on your own before watching this video!
Рекомендации по теме
Комментарии
Автор

Also, thank you all so much for 100 subscribers! It truly means a lot to me that so many people are interested in following my content and I hope you've been enjoying and that I can continue to deliver good content.

hyper-neutrino
Автор

Quick addendum, thanks to UnrelatedString for noticing - `[line[k * 4 + 1] for k in range(len(line) // 4)]` is the same thing as just `line[1::4]` using Python list slicing. You get a string instead of a list, but it's a whole lot simpler this way.

hyper-neutrino
Автор

My solution is similar, but I used an array of deques. I think this greatly optimizes the second cycle.
P.S. Oh, I heard at the end that initially you also solved the problem with pops and pushes)

PurpleDaemon_
Автор

Wow clean solution! Definitely took me some more lines, I'll remember re.findall for pattern matching (i used splitting on spaces and then hardcoding getting elements of this arr to get the numbers)

hjdeheer
Автор

I also parsed the stacks but saw other solutions where they just manually created arrays with the letters. Obviously not as "good" of a solution, as it is specific to their puzzle, but any thoughts on this? Would it have been faster?

tuskiie
Автор

Your solutions are definitely very geeky, but if you would code like this in a corporate codebase, your colleagues would most probably kill you :D
Even if you get back to your code some longer time later, you will spend quite some time, to figure out, what the heck were you solving here.
But as a demonstration of quick and clean solution, I have nothing to reproach.

ErikMeliska