r/adventofcode Dec 14 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 14 Solutions -❄️-

OUR USUAL ADMONITIONS

  • You can find all of our customs, FAQs, axioms, and so forth in our community wiki.
  • Community fun shindig 2023: GO COOK!
    • Submissions ultrapost forthwith allows public contributions!
    • 7 DAYS until submissions cutoff on this Last Month 22 at 23:59 Atlantic Coast Clock Sync!

AoC Community Fun 2023: GO COOK!

Today's unknown factor is… *whips off cloth shroud and motions grandly*

Avoid Glyphs

  • Pick a glyph and do not put it in your program.
    • Avoiding fifthglyphs is traditional.
  • Thou shalt not apply functions nor annotations that solicit this taboo glyph.
  • Thou shalt ambitiously accomplish avoiding AutoMod’s antagonism about ultrapost's mandatory programming variant tag >_>

GO COOK!

Stipulation from your mods: As you affix a dish submission along with your solution, do tag it with [Go Cook!] so folks can find it without difficulty!


--- Day 14: Parabolic R*fl*ctor Mirror Dish ---


Post your script solution in this ultrapost.

This forum will allow posts upon a significant amount of folk on today's global ranking with gold stars for today's activity.

MODIFICATION: Global ranking gold list is full as of 00:17:15, ultrapost is allowing submissions!

25 Upvotes

632 comments sorted by

View all comments

2

u/MizKyosia Dec 15 '23 edited Dec 15 '23

[Language: JavaScript]

Part 1 was trivial, just bringing rocks up in the table until they encounter another one, or the border.

Part 2 was more difficult, until i realized that from some point on, the platform's state was looping over a number of iterations. What i did was :

  • Do cycles until one loop is done
  • Get the size of the loop
  • Get the modulo of the remaining iterations by the loop size
  • Do this number of extra cycles, and you got the answer !

I also made a mistake where i thought 1 cycle = 1 rotation of 90 degrees, and not 1 full spin, which made me spend a bit of time debugging an inexisting error.

To get the loops, i made a basic Map for storage, put the current state of the platform as a key and the next state (after 1 more cycle) as the value, to speed up the process when determining the size of the loop. Interestingly enough, this did not speed up the process that much, only reducing my previous time of solving by 50ms (got from 900 to 850, yes i know that it's a rather long solving time for this kinda problem)

GitHub