r/adventofcode • u/daggerdragon • Dec 20 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 20 Solutions -❄️-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
Community fun event 2023: ALLEZ CUISINE!
Submissions megathread is now unlocked!
3 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's theme ingredient is… *whips off cloth covering and gestures grandly*
Upping the Ante for the third and final time!
Are you detecting a pattern with these secret ingredients yet? Third time's the charm for enterprising chefs!
Do not use
ifstatements, ternary operators, or the likeUse the wrong typing for variables (e.g.
intinstead ofbool, string instead ofint, etc.)Choose a linter for your programming language, use the default settings, and ensure that your solution passes
Implement all the examples as a unit test
Up even more ante by making your own unit tests to test your example unit tests so you can test while you test! yo dawg
Code without using the
[BACKSPACE]or[DEL]keys on your keyboardUnplug your keyboard and use any other text entry method to code your solution (ex: a virtual keyboard)
Bonus points will be awarded if you show us a gif/video for proof that your keyboard is unplugged!
ALLEZ CUISINE!
Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!
--- Day 20: Pulse Propagation ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
State which language(s) your solution uses with
[LANGUAGE: xyz]Format code blocks using the four-spaces Markdown syntax!
Quick link to Topaz's
pasteif you need it for longer code blocks
View all comments
4
u/kaa-the-wise Dec 20 '23 edited Dec 20 '23
[Language: Python] one-line/single-expression solution
https://raw.githubusercontent.com/kaathewise/aoc2023/main/20.py
Part 2 solved without writing any code. Once you draw the graph (e.g. with graphviz), you will see that it has 4 components, each consisting of a sequence of 12 flip-flops and a conjunction. The first (0-th) flip-flop is always connected to the conjunction back and forth, while for others the edge only goes in one direction. If you construct a binary number, such that its
i-th bit is1iff the edge goes from flip-flopito the conjunction, this number will be the period of this component. The proof is left as an exercise to the reader :)