r/adventofcode • • Dec 12 '18

SOLUTION MEGATHREAD -šŸŽ„- 2018 Day 12 Solutions -šŸŽ„-

--- Day 12: Subterranean Sustainability ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 12

Transcript:

On the twelfth day of AoC / My compiler spewed at me / Twelve ___


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 00:27:42!

20 Upvotes

257 comments sorted by

View all comments

Show parent comment

5

u/jayfoad Dec 13 '18

Sure it's hard to read if you don't know what any of the unfamiliar symbols mean. How would you all feel about the readability if I translated them into English? So instead of:

f←{v[uā³ā‰0 ĀÆ1↓(5,5+ā‰¢āµ)ā“0 0 0 0,āµ]} ā next generation

You might get this:

f←{v[u indexof transpose 0 -1 drop (5,5+count āµ) reshape 0 0 0 0,āµ]}

This is pretty much how I would read it aloud anyway.

Braces enclose an anonymous function, and āµ refers to its argument. So starting from the right we prepend 4 0s to the vector argument, reshape it to a 5 by (5 + length of vector) matrix, drop (remove) the first 0 rows and the last 1 column, transpose it so it's tall instead of wide, and then for each row look up which row of u (a matrix of all 32 patterns) it matches. Finally we use these numbers to index into v, a vector of the replacement values corresponding to each of the 32 patterns.

I guess you also have to know that reshape repeats its argument as many times as necessary to fill the required shape, so 3 3 reshape 'ABCD' gives this:

ABC
DAB
CDA