Advent of Code 2023 Day 14: Parabolic Reflector Dish

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

0:00 Part 1
4:50 Part 2

(Disclaimer: I receive commissions on paid memberships through my link, but Codecrafters is not a sponsor of this channel, does not endorse any of my content, and does not review any of my videos.)
Рекомендации по теме
Комментарии
Автор

Wow, this is insanely clever, yet results in such simple, short and clean code!

deraileddash
Автор

Nicely done. I did the same approach, first manually by printing it out to the terminal and then automating it. Your solution is really tidy!

mgeo
Автор

for part 1, I did it in another way without the need to flip or change the order of the elements of the original matrix. For each rock I looked at the elements above it, if I encounter a # i set the value of that rock to len(matrix) - i_cord of row_boulder +1. If you end up at the top of the matrix, i set its value to len(matrix). If I encounter another rock I set the value of the rock i am evaluating to encountered rock value - 1. Then I just sum all up. It was quite easy to code, but them I got stuck with this approach for part two. Don't know if there is some sort of way to make it work also for part 2.

matteolugli
Автор

I think we can use the Load as a hash or identifier for the grid at any point after a spin cycle. so we can track the load (an int) instead of an entire grid.

wusswuzz
Автор

Really well done. And thank you for the explanations. Could I ask you to explain how open(0).read() opens the test.txt file please.

tommygibbons
Автор

So its an abacus, where some of the beads are stuck to the rail.

Vancha
Автор

Using tuples of 100 strings as cache keys, array entries and search values feels so wrong but so right, i know, but maybe show the audience that data hashing is used in these cases, to not blow up the RAM? 😅

maxxbrandt
Автор

can anyone tell in which line exactly rotation is happening in part 2...cuz all i see is reversing the rows (in 3rd line of for loop) ??

AyaanKhan-iyvh
Автор

this is cool! when i detected a cycle i just incorrectly assumed the cycle length is the iter count, instead of accounting for when cycle begins

gradientO
Автор

I have some simple functions that examine the fields above, left, below, and right and move the rocks if they're free. For part one, this posed no problem, but for part two, it became quite performance-intensive. I discovered that running through 1000 cycles yielded the same result as running through cycles. The only connection between 1000 and is that 1000^3 equals Can anyone explain if this was just luck or if there's an actual reason?

smcr.konsti
Автор

You could just do table instead of set+array like table[string, int], or in Python it's dict really

mb