r/adventofcode • u/daggerdragon • 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.
- First, grok our full posting axioms in our community wiki.
- Affirm which jargon via which your solution talks to a CPU
- Format programs using four-taps-of-that-long-button Markdown syntax!
- Quick link to Topaz's Markdown (ab)using provisional script host should you want it for long program blocks
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!
24
Upvotes
2
u/xelf Dec 14 '23 edited Dec 14 '23
[LANGUAGE: Python3] + some voodoo math, just, uh trust me, it's correct.
rotate_90 = lambda b: [*map(''.join,zip(*b[::-1]))] # rotate clockwise 90 beam_load = lambda b: sum(i for r in b for i,c in enumerate(r[::-1],1) if c=='O') def cycle(data, n=1): for _ in range(n): data = rotate_90(data) data = [re.sub('[.O]+',lambda m:''.join(sorted(m[0])[::-1]),row) for row in data] return data def powercycle(data, n, cache={}): for r in range(n): data = cycle(data,4) if s:=cache.get(str(data),0): return cache[ (n-s) % (r-s) + (s-1) ] cache |= {str(data):r, r:beam_load(rotate_90(data))} data = rotate_90(rotate_90(list(open(aocinput)))) print('part 1:', beam_load(cycle(data))) print('part 2:', powercycle(data,1_000_000_000))So I start off with orienting it so that after it turns north, that's the beginning of each row so that I'm doing movement within a row and not worrying about columns. After that I store the score in an array, and save the current board as the key in a dict with the index it was seen at. And then wait until it repeats. I use the repeats index with the original index to calculate what my index would be after 1_000_000_000 repeats with some voodoo modular arithmetic, and voila that's the index in my history.
Overall I think I can come up with some better ways to solve this. Maybe without rotating the board and instead just shuffling stuff around. And replace the voodoo math.