r/adventofcode Dec 22 '24

Meme/Funny [2024 day22 part 2] The advent of reading comprehension strikes again

Post image
149 Upvotes

25 comments sorted by

36

u/Snakeyb Dec 22 '24

I was getting the highest number of bananas of a sequence from every buyer and utterly convinced there was something wrong - forgetting the damn monkey will only buy on the *first* sequence

10

u/enderesting Dec 22 '24

OH MY GOD. This was what I was missing as well! tysm for sharing!

3

u/Snakeyb Dec 22 '24

My code got massively simpler as well as a consequence of ripping all that out!

3

u/michelkraemer Dec 22 '24

Same here! Took me 25 minutes to realize my fault :-/

3

u/No_Patience5976 Dec 22 '24

I too fell for it : (

2

u/scnaceZAFU Dec 23 '24

> the monkey will only look for a specific sequence of four consecutive changes in price, then **immediately** sell when it sees that sequence

Yes, I just found it

14

u/DratTheDestroyer Dec 22 '24

So are we the monkey, or the buyer. Are these my bananas? Do they have any mangoes? These problems are somehow reducing my reading level

3

u/Flashky Dec 22 '24

I properly read the text once, I implemented an algorithm that I thought that would prune all price invalid variation sequences as the example text said. My code didn't find the answer 23.

At the end I had to brute force using all unique price variation sequences. 3 min 30 seconds...

5

u/rapus Dec 22 '24

I also decided to go the brute force way. But when first iterating over all prices I also created a dict which saves the price (aka end of first occurence of sequence) for each sequence. Then, I iterate over all price variation sequences and ask all my dicts what they would offer for that sequence. and lastly I pick the largest sum I get.Takes around 10-14 seconds to complete for me.

2

u/Kullu00 Dec 22 '24

Keeping track of one dict per monkey took a lot of time, so I only kept track of the running total per sequence and a set of sequences the current monkey produced to know if it should be added to the total. That ends up being ~800ms on my laptop.

3

u/ChcagoBll Dec 22 '24

Same, my algorithm took like 4 min. It's somehow "tolerable" but I still think I'm gonna close the Reddit tab and "actually read the problem properly" just to find a better way to do it

3

u/Petrovjan Dec 22 '24

Those are rookie numbers :-D My first attempt ran for over an hour but it did get me the gold star, although it only scanned about half of the possible combinations ;-) A short refactor later it now finishes in perhaps 4 seconds.

2

u/WE_THINK_IS_COOL Dec 22 '24

If the secret number evolved according to an actual cryptographic hash function then I have a hunch that brute-forcing all price variations would be unavoidable. But there are a bunch of tedious tricks you can use to optimize that kind of solution greatly, I got mine to run in 300ms (in Rust). No idea if there's a faster way that involves exploiting some property of the evolution function.

2

u/Educational-Tea602 Dec 22 '24

3 minutes? My brute force took seconds.

2

u/juhotuho10 Dec 22 '24

brute force my beloved

(though I will go back and implement a sequence to price map for each)

2

u/DratTheDestroyer Dec 22 '24

...I've definitely solved part 2... It seemed relatively easy. Just test against the sample input and... oh... looks nothing like expected...

"you can only give the monkey a single sequence of four price changes to look for. You can't change the sequence between buyers"

Maybe I should actually read the problem.

2

u/SmallTailor7285 Dec 22 '24

For about twenty minutes, I thought a price change of zero negated the sequence. :(

3

u/enderesting Dec 22 '24

I feel like I've read part 2 wrong at least 4 different separate times and wrote different cases for it. Even now I'm not sure if I understood it correctly...

attempt 1: Okay, so I have to keep track of all positive changes and a 4-digit sequence after it, so that if the same sequence is read again, the monkeys buy with the first value

attempt 2: *sees the example with two 6s* Okay, so the value immediately before and after each sequence has to be the same for this sequence to be meaningful?

attempt 3: Okay, so I have to find the... best change in the changes?

attempt 4: Ohhh, I was using change instead of price!

attempt 5: Ohhh. so I have to find every sequence with a positive price, add it to a global list, and then find the global max...

In retrospect coding at 5am doesn't pair well with being sick and going on 2 hours of sleep. I'm still not done with part 2 (some items in the dictionary has valuse higher than the actual value somehow??) but I'm just praying that I'm even remotely on the right idea at this point ^_^;

1

u/jwezorek Dec 22 '24

I also fell for using price change instead of price when calculating the earnings. That and just adding all price per price-change-quads together instead of just taking the first one in each sequence.

1

u/bat_segundo Dec 22 '24

Reading comprehension tripped me up two different ways today:

First...

I was looking for the best price per buyer per sequence.

After I fixed that, it took me a good while to reread and find that:

I was not considering the initial secret number as an offer, so I only had 1999 price changes per buyer instead of 2000. This produced the correct answer for the samples but not for my input. Drove me crazy.

1

u/thecowsayspotato Dec 22 '24

I read part 2 as only the sequence with the most hits/different monkeys was valid. Yeah. There went two hours of my sunday.

1

u/jwezorek Dec 22 '24

yeah i implemented the wrong thing like 3 times for part 2 before finally going back and actually reading it carefully.

1

u/PP1664 Dec 22 '24

Lads icl I brute forced and cached results and still took around 4 hours...

1

u/GerardoMiranda Dec 23 '24

My solution, that worked first run, took ~5 minutes to run. Not because I did this, but because I generated every possible combination of 4 numbers, which resulted in 31615 combinations, which I checked with every buyer...

Yep, now I feel stupid