Advent of Code 2023 Day 14: Parabolic Reflector Dish

Поділитися
Вставка
  • Опубліковано 22 лис 2024

КОМЕНТАРІ • 26

  • @deraileddash
    @deraileddash 11 місяців тому +3

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

  • @Vancha112
    @Vancha112 11 місяців тому +1

    Unbelievable :o great work

  • @m1geo
    @m1geo 11 місяців тому +2

    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!

  • @charlescairney
    @charlescairney 11 місяців тому

    This was super clean 😁

  • @wusswuzz5818
    @wusswuzz5818 11 місяців тому

    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.

    • @xavier29771
      @xavier29771 11 місяців тому

      You could theoretically have two seperate grids with the same load probably which would break this approach no?

    • @wusswuzz5818
      @wusswuzz5818 11 місяців тому

      @@xavier29771 I just saw this lol. Yep you are 100% correct.

  • @Vancha112
    @Vancha112 11 місяців тому

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

  • @Ziteyt
    @Ziteyt 11 місяців тому

    thank you hyper neutrino

  • @matteolugli1607
    @matteolugli1607 11 місяців тому +3

    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.

    • @mathcat4
      @mathcat4 11 місяців тому

      I believe the best way to do p2 with this approach is also to apply a 90deg rotation 4 times - lmk if there's a better approach.

    • @lerbyn
      @lerbyn 11 місяців тому

      @@mathcat4 I tried that and it took forever

    • @Vancha112
      @Vancha112 11 місяців тому

      ​@@lerbynsame, my code was probably very slow, but i wonder if you can code that up in a naive way and end up with anything fast :0

  • @tommygibbons9791
    @tommygibbons9791 11 місяців тому +1

    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.

    • @hyper-neutrino
      @hyper-neutrino  11 місяців тому +1

      Ah, that's done by my aoc utility script, which just runs python3 solution.py < test.txt (or in.txt). You can find my script on my github repo

    • @tommygibbons9791
      @tommygibbons9791 11 місяців тому

      @@hyper-neutrino Thank you

  • @gradientO
    @gradientO 11 місяців тому +1

    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

  • @AyaanKhan-iy4vh
    @AyaanKhan-iy4vh 11 місяців тому

    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) ??

    • @hyper-neutrino
      @hyper-neutrino  11 місяців тому +1

      The zip(*grid) is a diagonal flip and the row reversal is a horizontal flip. Combining these results in a rotation.

    • @AyaanKhan-iy4vh
      @AyaanKhan-iy4vh 11 місяців тому

      silly me😔...thanx:)

  • @smcr.konsti
    @smcr.konsti 11 місяців тому

    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 1000000000 cycles. The only connection between 1000 and 1000000000 is that 1000^3 equals 1000000000. Can anyone explain if this was just luck or if there's an actual reason?

    • @hyper-neutrino
      @hyper-neutrino  11 місяців тому

      It means that 1000 happens to be your (1B - offset) % (cycle length - offset) + offset value. It could also be a coincidence that the total load value is the same even though the grids are different.

    • @smcr.konsti
      @smcr.konsti 11 місяців тому

      @@hyper-neutrino you are right. It was just a coincidence. I was a bit confused because they're both powers of ten, and the test case also returns the correct value at 1000 cycles. The correct approach would probably be to cycle until you find a readapting loop in the cycles and skip the remaining iterations. I will adjust my solution. Great videos by the way, they helped me on a few tricky problems although I use c++ for this years aoc

  • @maxxbrandt5822
    @maxxbrandt5822 11 місяців тому +1

    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? 😅

    • @hyper-neutrino
      @hyper-neutrino  11 місяців тому +1

      I could make a separate video about hashtables/hashsets sometime! (And other data structures)

  • @4mb127
    @4mb127 10 місяців тому

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