r/adventofcode • u/daggerdragon • 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!
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
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:
You might get this:
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: