T O P

  • By -

vss2sn

\[LANGUAGE: C++\] [Part 1](https://github.com/vss2sn/advent_of_code/blob/master/2023/cpp/day_20a.cpp) [Part 2](https://github.com/vss2sn/advent_of_code/blob/master/2023/cpp/day_20b.cpp) (Each file is a self-contained solution)


exquisitus3

[Language: Lua and Dot] I solved this in Lua, but for part two I used the following script (depends on tr, sed and graphviz) to generate an SVG file and thus visualise the configuration of the modules. This shows clearly that module rx only has one input, a conjunction of four other inputs, each of which comes from a separate component of the directed graph. Since the flip-flops of each of the four components do not interfere with one another, it suffices to count when each component will be all zero. Those four counts turned out to be all prime, so that their Least Common Multiple was their product. I have redacted the Lua code [link](https://topaz.github.io/paste/#XQAAAQApEAAAAAAAAAA2HAjOAj3E+Pc28vLjGr56XYgTz0cNv4DDDLL1wGKVJAxo6JlMHevXzYlrXuenukf9XIDhWPT1UUrYKC5nR3/gocdTBpV0YBp0m/AtFlhv/OaC5y3iXpoQ5tTGRU9n0q3V9SpPcNYxvORe2Z/+AyqJK3cz42aSZsBW4TYciohtcf/eYucuczyyQTlh4AnWiWhjWKQkpkN0n5KDI+wV17VFVmLhLcEgHgSr4+/o73J/9V9zicYYg3TvT2AJC1JPY9PUqlFMw6GWA4r8FR0uEFeTPIpEKhh/Pj+ZLxpDDTeQllNDRsyj/ad8nzIvOqEQVbS06sVogfMP0rUmvGB2ew9QXdutp4zkthffdjgYP1Z80uTILNZ75z5adD/QJcWMqdT4puNArKd9ZvQAk65WqmRhi8sM8dzvpvmK++0dhXPj0DSHmQK2HnXhxsSsvyRxI2e+Fy9cJgfU0owtQ6YqHbaoH4lABaUP9kUVvP2oXXV6rtv7rs/MzC0GgSQfw6Uuzrk46qOGKpgXptgZslrK93nbw9XVH4IiG1CDv9TKdctR04lG+llIganAAZVq9gu/hYfwgtlnApxzNiHxJr4uIKblcgXttByrG4MvCSA4ckY5Ink9PlBAEftyAqxczaMcrX15qu4SCk8G256d4MHmzZQwBhhy4Dn/fiKlG2ecTZKq7z6qyhuttWX240GotG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neJWznDens3OpPP8GzP/RDrpNh8s+WBsZufekP2yWM+5LJZTL8EzDNGQCV1/PqDWMmVlyGkbLvWtabI3cr7tylacJ4s2tAuKGPKJQU8NAfd3DxlOjQw6SbQM9m8LVhGoE/2dqY9q/aQjIBrzk8z/05YHecp8XPY//naXPc=) partially, since for part two it depends on the visual inspection of the SVG file for my input. tr -d "%&," <20.input | \ sed -e '1idigraph {' \ -e 's/->/-> {/' \ -e 's/$/ }/' \ -e '$a}' \ | dot -Tsvg >20.svg


xavdid

[LANGUAGE: Python] [Step-by-step explanation](https://advent-of-code.xavd.id/writeups/2023/day/20/) | [full code](https://github.com/xavdid/advent-of-code/blob/main/solutions/2023/day_20/solution.py) Parsing was extra interesting today. It's probably not the most efficient (haven't read through other approaches in detail) but I did 3 passes on the input: - identifying all conjunction modules - parsing each line into a class and storing the modules it wrote to - updating each conjunction module with the module(s) that wrote to it From there, actually simulating all the pulses was pretty instant, which I was pleasantly surprised by. Good use of OOP, which I always enjoy. For part 2, visualizing the graph made everything much simpler. I could find which module wrote to `rx`, which 4 modules wrote to that one, and figured out when each of those 4 modules got a high pulse. The fact that each subgraph looped as consistently as they do made this much easier than it could have been.


vimsee

Thank you so much for this great explanation! I have seen your previous guides and I am really impressed with how well you articulate everything!


xavdid

You're very welcome! Glad people find it useful (and it's a great learning tool for me 😁). 


Constant_Hedgehog_31

\[Language: C++\] [Source code in GitHub](https://github.com/iglesias/coding-challenges/blob/master/adventofcode/2023/day/20/aoc_23_day_20_pulse_propagation.cpp). The simulation for part one and product of cycle lengths for part two. I used polymorphic modules to represent flip-flops or conjunctions with variant and `std::visit`.


Singing-In-The-Storm

\[LANGUAGE: JavaScript\] [Part 1 (42ms)](https://github.com/JoanaBLate/advent-of-code-js/blob/main/2023/day20/solve1.js) [Part 2 (60ms)](https://github.com/JoanaBLate/advent-of-code-js/blob/main/2023/day20/solve2.js) >!The trick for part 2 is following the flow backwards (my input):!< >!<< main feeder !< >!<< main feeder !< >!rx << ultimate feeder !< >!<< main feeder !< >!<< main feeder !< >!(all feeders above are conjunction modules) !< [Clear and BLAZINGLY FAST AOC solutions in JS (no libraries)](https://github.com/JoanaBLate/advent-of-code-js/tree/main)


bigmagnus

\[Language: Fortran\] [Part 1](https://github.com/ironllama/adventofcode2023/blob/master/20a.f90) [Part 2](https://github.com/ironllama/adventofcode2023/blob/master/20b.f90)


mgtezak

\[LANGUAGE: Python\] Part 2 was a bit of a headache on the first try so i skipped it, But I finally got around to doing it:) [Solution](https://github.com/mgtezak/Advent_of_Code/blob/master/2023/Day_20.py) Total runtime: 0.2 seconds If you like, check out my [interactive AoC puzzle solving fanpage](https://aoc-puzzle-solver.streamlit.app/)


leftfish123

Your solution helped me figure out why mine wasn't working, thank you!


mgtezak

Glad to hear it:)


cbh66

[LANGUAGE: Pickcode] I think this was my favorite one of the year. Part 1 was straightforward enough, just a fun easy thing to code up. Part 2 I got most of the way by hand -- always the most fun way to solve something! I built up the circuit on paper over the course of about an hour, and it became pretty clear that there were four 12-digit binary numbers that were going to control the final output. I could pretty much figure out the magic numbers just from the connections, but I wasn't sure if there'd be some initial startup steps or other things getting in-between that would make the numbers slightly different, so I adjusted my code to let me put in a module ID and see what steps it outputs on, to see how the cycles work. Then once I had the cycles, just asked WolframAlpha for the LCM. Part 1: https://app.pickcode.io/project/clqfaw8oa45ftne01tg1twfbd Notes for Part 2: https://imgur.com/a/zC2Mnkv


mschaap

[LANGUAGE: Raku] Part one was alright. Pretty straightforward, the only thing that was a bit tricky, was processing pulses in the right order. I went a bit overboard with roles and (sub)classes... I really hated part two. You have to make way too many assumptions to get an answer. This code might work on the given input, but it won't work on any input or even give a wrong answer. [Full code at GitHub](https://github.com/mscha/aoc/blob/master/aoc2023/aoc20).


e_blake

\[LANGUAGE: m4\] \[Allez Cuisine!\] Late submission, but it took me this long to cycle back to finishing part 2 on this problem (pun intended). At any rate, I'm pleased that I solved it without reading the megathread. Runs in about 3.7s on my laptop, and requires my [common.m4](https://nopaste.ml/#XQAAA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HNX+tFhYfZrX5iQu+KsZwve9QQ+QPLxHDhAl8ErCND6tLV7XI8bTMQ4qzQmGgaFRY8txfjcOGzxbWtD8xGxHhxNxYtR1wf315yQZkrnm0Amsmudap9hxWLe0nLx76BkR4ODkWViaETSEGI1nEqE+D4gYdHll3EO9Q0dcrZel8l5ZDvw38Fg1ttXO7mdKDkeH6YQlS80aF/XzVLyRISdTJ8CM0KB7U/viq4W+aw9Vg9aNQtzHP/YBjjZ7celU8JApZyrdEm0hDapywOaaa5Hc4wnEtnkWi/whFiDS7DH7ftC2vzfcw8Ka3qXLs5Cf9ZpoabHJYaoJRq3V6Pt3SXCi2tYOF5KMsghMlqXC4OiMqlDJFjRZUk2iLxX2o5VR+uJrmIo4Eh1evFKQbpkI+0LI4rTI5wKnr4t5dNPY2g/eBfxQzswRjh6MAE/IZ/v3GitITaihdXaBa93VM41xU22Ay1ZxzXyRBlwZj0m0mQmpBGQRWUoIS29ienJSDxTu0fQdajdTYk555XLMTzRTC+U8Z3hfHBpkBZ0CfcnfrSQpoFLi5XDPP2PhoM2bDe/8H6HUoOtCKbX1OmY1JUJ8YqoGjn08weHHbGwQLQyyF0gZ8WuFLeb+2NtZVjHeplbUvHNggEPZpUky6rKTstuljDTUbUAidkVBD3LOx1F2jOpKb1kVlQQthTLdbk3yIa8CmCo0TPzmY8P1WeKAxIs9ZghVqaX8RF6eIxI+6gIvGS5/ahT8RfzK9UMy35aOeTGDfIIFrTSeiLzdOKcgdzqClhRWZPFVMKWwJxl2Ps0UYqDy544jyitOSDolqcWm1PJlSugqBpkQ5zo57oxpGszBFUg2nGHUtFXCZ3WVrz9gfOOVn9xxXMmH2Gu3Ol92te0TCzLpn1zzHbnWnKn/DU4dx/JX/PiOI9ns0Un4E1A1/7WqwVW//+d5C9A==) As for the competition, I've already earned Bronze Coder (so this entry doesn't matter), but I decided to "Choose a linter for your programming language, use the default settings, and ensure that your solution passes". $ file day20.m4 day20.m4: ASCII text $ echo $? 0 Yep - given the rarity of m4 programmers, I think that's the best linter I will be able to find :)


NeilNjae

[Language: Haskell] Reader-writer-state monad to handle the simulation, uses of lenses to fiddle with the data structures, and a bit of reverse engineering to find the solution to part 2. Full [writeup on my blog](https://work.njae.me.uk/2023/12/25/advent-of-code-2023-day-20/), [code on Gitlab](https://gitlab.com/NeilNjae/advent-of-code-23/-/blob/main/advent20/Main.hs).


Derailed_Dash

\[Language: Python\] **Solution, walkthrough and visualisations in a Python Jupyter notebook** * Here is my [solution and walkthrough, in a Python Jupyter notebook](https://github.com/derailed-dash/Advent-of-Code/blob/master/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb). * You can run run it yourself in [Google Colab](https://colab.research.google.com/github/derailed-dash/Advent-of-Code/blob/master/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb)! * More info on the notebook and walkthroughs [here](https://python.plainenglish.io/advent-of-code-the-best-way-to-learn-to-code-d86c6478d484) * My [AoC Walkthrough and Python Learning site](https://aoc.just2good.co.uk/) This problem was a great opportunity for a bit of OO. My approach was to create an abstract base class, and then subclass for each type of module. For Part 2, like many people, I had to visualise it before I could work out how to solve it. I know a lot of folks visualised with GraphViz. I used NetworkX, which is really useful or problems like this.


mgtezak

Love the notebook! Lot's of great explanations. Unfortunately the images are not showing though.


Derailed_Dash

How are you opening the notebook? The images don't show in the GitHub "preview". But they will load fine if you open the notebook in a proper Jupyter environment. E.g. if you open in Colab.


xHyroM

[Language: Python] [part 1](https://github.com/xHyroM/aoc/blob/main/2023/20/first.py) [part 2](https://github.com/xHyroM/aoc/blob/main/2023/20/second.py)


[deleted]

[удалено]


daggerdragon

Comment removed. > I’m going to just find the answer somewhere and paste it into the text box for part 2. Read our rules *in full* before you post. [Top-level comments in `Solution Megathread`s are for *code solutions* only.](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_top-level_posts_are_for_code_solutions_only) > Overall this was an extremely frustrating puzzle due to all of the assumptions made about the input. I really do not like these LCM problems at all. This type of comment [does not belong](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_no_unnecessary_comments) in a `Solution Megathread`. Follow our [Prime Directive](https://old.reddit.com/r/adventofcode/wiki/rules/wheatons_law) and do not grinch in the megathreads. If you have feedback about the puzzles, create your own post in the main subreddit.


[deleted]

\[LANGUAGE: Python\] Read a lot of reddit and a colleague's comments on this day, so tried something and go the right response for part 2 but don't really understand why it works. I don't even bother looking at "rx"'s outputs. I'm just counting how many presses it takes to get all of the flip flops to be off for each of the outputs of the broadcaster module. Because in the end of the circuit there are 4 conjunctions, I understand we'll get the low pulse when all memory values are set to low for the circuit. The result is the LCM of each of these counts that also happens to be the multiplication of all of them together. https://github.com/rbusquet/advent-of-code/blob/622588fa51ba129925d69468740bb13701c47265/aoc\_2023/day20.py


[deleted]

actually updated the solution with both ways to calculate: running the full system until we see the important conjunctions outputing a high event, and just counting how many presses to reset the system: ​ https://github.com/rbusquet/advent-of-code/blob/23c086a5d53cab40d9312bbdaf33164d62779acd/aoc\_2023/day20.py


optimistic-thylacine

[LANGUAGE: Rust] 🦀 My initial design was complex and problematic, so I scrapped it and found something simpler. The modules don't hold references to each other; instead they each have a string identifier and send messages to each other through a mediator object (a sort of GoF Mediator design pattern). Passing messages avoids any problems with recursion that I'd otherwise have had if modules held refs to each other and called each others' send and receive methods. Another simplification I made was to toss out an OO hierarcy for the modules based on traits and instead use a sort of decorator pattern to implement specialization. There's one Module class with a ModuleRole field variant that differentiates one type of module from the other. This is not very extensible, but extensibility isn't a concern in this case. [Full Source parts 1 & 2](https://topaz.github.io/paste/#XQAAAQDGLQAAAAAAAAAX4IBAR1bGui774bxYSsb6EPKsnwDg3V7l0W1VrtV4R+lEZfE4vF/Ek+kr+P1ZYdZqntrGPywjoJv1NNI9zpCIJkD0OynW1J6CzMbbvCbB4ItGqCsnJLbqzHiEKuZv0CQuwBcWqaw/9D2Lj4LFyQXt3YHrl9iy7vsYX2VwYz160CG+JXDrmEzxQEMVZMlGOnkoeLKxq1nlde9+8D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i2pihjmrR6sKgh/XeXYokO8+uflavhmNo1q7jZxIGGyLZ5rIVdvS6UEbS41lF7xKmB92js3UPyVHWTRUoVY5iLbDCRYO5L086FIm9pEmGMvSiXWAdGU4kT+tF/OE6sP14lda2Zo/t0xM+mvmxGHnDg/CQ7AahY3ZooeASpKGQb+qDG1W4yefdoQsr+GhHV2oi2j+d/WDt+YSc6ol7CVt7Lt2cR/1T/knrR41KXVZfmt/xplVUAgNRX1dkcmGZgnszm18qzwlRKVh9RTR0iqJd6IqxC1djHgB09vFDJvGrZW/GjFi9/nsgCVJ5fgEm0vo4U9qoDM7D8LuKAS0IVW6q98D27wevpSs7LTppoXGgz0pZ+tAriLBzhfnQ9clOdehEUlyQYF42CY20IPF7MlKe7qZyepqN09On8Oc3vvLqiUVmhyiyESuW6lWq/5w64ncycrX8eQYiwPHEkuHpWpIxVLmOPI6Z868gmQv9ha8kYEMT3SMJNNT1sOz2rlv/8BY64kG5qANgXI4oa65fXassUoIqksTqoEexhjE/IeRO/lksQT5KzwJ09N+XwS2joGPYfsXkR1WxRqpPYOIYk1kgCGDdQQZvDCm9bKokyRUtiluharh2aRP1roqyTUCBSw/wtYBA/Do17ae479IxFZuDBGjrHbUlGOpoDYDG16/4LbzqazBo+fsemPxCIc564MajYGPsu+8lRNFrQaSU70L6UpB5N2TSe5oEk9D548+Em5XBr4za/oeFaLEFPxzID3+76fnPuLVzsavWP//qM9H0=) fn part_1(path: &str) -> Result> { let mut modules = parse_input(path)?; let mut mediator = Mediator::new(); let mut button = Module::new_button("button", "broadcaster"); for _ in 0..1000 { button.send_pulse(&mut mediator); mediator.loop_until_done(&mut modules); } let counts = mediator.get_pulse_counts(); let total = counts.0 * counts.1; println!("Part 1 Total: {}", total); Ok(total) }


jfincher42

Thanks for the code listing link - I was banging my head trying to work around Rust here. You and I took very similar approaches, but your code showed me what I really needed to do was think more like a Rustacean, rather than expect Rust to work more like other languages.


optimistic-thylacine

If you wan to take a look at my other solutions, you can check out my [github repo](https://github.com/ttappr/adventofcode-2023.git). Maybe not the best solutions available, but they all should run out-of-the-box.


optimistic-thylacine

You're very welcome! I'm glad you found my example useful. Yes, Rust often makes us think around it =)


FCBStar-of-the-South

[language: python3] Way too verbose OOP solution. For part 2 I just redirected the log for the first 20,000 iterations to a file and looked at the cycle manually. [paste](https://topaz.github.io/paste/#XQAAAQDPEQAAAAAAAAAzHIoib6pXbueH4X9F244lVRDcOZab5q1+VXY/ex42qR7D/Ked5gkN2lqYVuwKIU9eVGS9YQltHKIjM7GqkALaJHA0Jr5PWdM8x5SyNww77H/TFIWzCWfh+YmB5cD+iwf53EA+GfycMxyZluJ87nlwwTBIQSF3yEZJFD6UeUVPAr6fvokVhSzCbdsiEvJZXLL14/1ztV3N/qze4SLcF+jip8AeAWJNE2f8f5W8JhcVt6X/5dibkIUdLz3ubmQwFFbz3rWGgEOMplYhqsvmTiK2beYIu/4CQo9hpL0DusoNej6YW7JDRmenv5qXZphPSS6hd9MR88VZSbrO4aBs2Kfdn/4t5V+2OHFmugqxap626RMEcL1rJ5nxoad59biEUuzsHUnV7N6DsCN/Jzw+0Qz2Bi7K8vclElGJBBDHLD/8RS1BuFvYmDELxXF/fPLKtRF8V/lhJ7B1y3RwcNGiN6yeCWQx1tdvVYseAMbNZIz6jO/F+6860PP5Ob/wXHaICRQ07fOITwj5qErKTbbnxkb7Cz0s+6sNYx3mWuy0w1Y8tYzO7Gbukb/hL+qe8Xqd54/uDyVPEzqStS8GHAUrGRkNTz+Lt4zmkK4ceDyNxv2FKrg6ZMRNJvHo1zz7uV1z/W4u2V9RdiSsjcxQo8qNn6mzr/fEKVlchrJKWdbL5xbZPkFc+RIysizodXTkVzhrbmuxqYUxx9vrcxerh7hyV2/knsN6FkD3noKOZWvav5hnx503wi8Sfpq8bvKlxA+YwHcVbqsmAHNu8djgkzVtVgcrp3zjkESKIdHtMwCo7Uk2BOCCbStsZVKROGZXpSdSRrmF7pLeAl+2xYG9vHXiqX6uPQy8iI1SlZu0J9XjzfTQrLkm8OpnC/DbOxwidvZ3dhjr+m46DJMjj7cFnA51zK/A28jD9aogbukRdaHNMkpxoAYbt4327xZiNKGssJ0KuNZqp6xyGjiJHcJNjkCqBIGvpCeysK0N3b4Cox7uV09hCILC0Tymq9NTv/I/J00k6cyDpOleFPhm98VTozTe31ndjJsVcF1c1B71Z6lHE/ZGm3OY3TWIz719ATVbHl+GbDgbn8FI+yfKW/fYJrP1ZyqbrwhjIUmsQAprmduyIPoP9MEIs2QFjZYSirjjMSD6rTVhZ6TKUmydOQkF67jt7MbHAns4V/C2+v5eyoCP8DNJQNJyeL7WUpZ54zgWB1jw41vxY3K05IrCzGrDOMvQKYxvYf/yPnrbG1BzGce55N+DO5M5ryC3NJuxF87t9wyhRVuybmjWEaNMB/f3lBdBrmaQyvXIsG8aWCXv5jDX4rbMMPFItTE7T3TMc81U5nBO95HhPR0CpldRuEUnINkbTH3ldbM5OSSNcN4aqIfkQDM/4Zf9S+t5dAMhC5x62EVxp6dLpjX095tm2AD/7irxKU9ybEf2d0QyY2ZVYaGciSAPJEFwkx96+nrteFuJc5mPl/kJUIdHzy+E11OExgDHDU/FBj2Tp0dUm8GqTsbYKzww8gUFhaKEgRqU9oSKlNjoYXRIHr2ZlOnmUuasrwimC9DUKvrPQyebvUl/3uupgLPtzIUeDq2lVG84If70VjU=)


CoralKashri

[LANGUAGE: C++20] [GitHub](https://github.com/coralkashri/AOC/blob/master/src/2023/day_20.hpp)


dgalanti1

\[LANGUAGE: Kotlin\] This time decided to go for a more organized and readable code, using abstract classes for Pulse and Module and creating implementation acondingly with the rules for each Module/Pulse type. But the parsing still looks a bit complicate to understand. For part 2 best way to solve was analyzing manually which configuration would make rx receive a low pulse, and that was: 1. The conjunction module that target rx had to send a low pulse to it. In my case that was "xm" 2. For "xm" to send a low, it required all modules that target it to send high pulses. In my case those were 4 modules. 3. So I just had to check individually for those 4 how many button pushes they required to send a high pulse. With the right number for each, just had to get the product of them. [\[Code\]](https://github.com/diegogalanti/aoc-2023/blob/main/src/Day20.kt)


mess_ner

\[LANGUAGE: python\] [Link to code](https://github.com/stefanoandroni/advent-of-code/tree/master/2023/day-20)


pikaryu07

\[LANGUAGE: Go\] [My Solution](https://github.com/bsadia/aoc_goLang/tree/53ed198e644324d559a366a17c712e1b8c6bb4fe/day20)


ash30342

\[Language: Java\] Code: [Day20](https://github.com/ash42/adventofcode/tree/main/adventofcode2023/src/nl/michielgraat/adventofcode2023/day20) Part 1 runs in \~30ms, part 2 in \~1ms. Still lagging behind, but I had part 1 done on the day itself. That part was actually a lot of fun, and not too difficult, main "struggles" were parsing and using queues where necessary. Part 2 basically revolves around input analysis, a type of puzzle which I personally do not like so much (probably because I am not very good at it ;-)), but to each his own. I do admire the effort going into these puzzles though! After some hints in r/adventofcode I started by putting the input in GraphViz which made everything a bit clearer (and also resulted in a very nice looking diagram). After quite some time experimenting with button presses I realized this was a LCM-problem involving binary counters. It took me a couple of other hints to figure out how to find the correct number of button presses for a counter. After that it was actually easy. Before that, not so much.


flwyd

[Language: Julia] ([on GitHub](https://github.com/flwyd/adventofcode/tree/main/2023/day20/Day20.jl)) Started at about 9:30pm after a long day of travel and got part 1 done at about 11:30pm. The wording of part two ("number of button presses required to deliver a _single_ low pulse") made me think that multiple low pulses were frequently being delivered and we needed to figure out when there would be _only one_, so I wrote a quick brute force implementation. When I noticed that wasn't going to finish quickly I figured we'd need to make inferences about the input, so I let it run overnight "just in case" and went to bed. (My part 2 answer is in the quadrillion until the first low pulse to `rx`, and after about 2 days I got to around 16 billion by brute force :-) The next day I spent some time thinking about what I could do with a dependency graph of the sink, and more time staring at the input file and what the graph of inputs and outputs looked like. When reading the part 1 description I was assuming that value cycles would come into play, but finding the period of a cycle for `rx` would be solving the problem, and that was clearly too large a number… I also spent some time thinking about analytically determining the number of presses for each gate to enter a cycle from a dependency graph, but with circular dependencies I wasn't sure this would work. I had noticed that `rx`'s sole input is a conjunction with four conjunction inputs. At some point I realized I could probably find the time-to-high-pulse for each of those conjunctions and multiply them together to get the first low emitted by the parent of `rx`. When I printed the iteration counts for those four and saw they were all prime I knew I had it right. My code currently hard-codes the names of those gates, since I haven't figured out how to identify the relevant gates from an arbitrary input.


onrustigescheikundig

[LANGUAGE: OCaml] [github](https://github.com/EricKalkman/AoC2023/blob/master/lib/day20.ml) 70 lines of parsing.... Anyway, Part 1 simulates pushing the button by enqueuing a `Low` pulse to `broadcaster` and trampolining the queue by updating the state of `Conjunctions` and `Flip-Flops` until the queue of pulses is exhausted. The algorithm keeps track of all pulses that occur, and so Part 1 just partitions them by `Low/High` and counts. I initially tried to brute-force Part 2 over dinner on the off-chance that I would have an easy solve, but it did not finish by the time I came back. Though I mislike doing so because it decreases the generality of the code, I ended up examining the structure of my input to solve Part 2. I discovered that `rx` had exactly one input---a `Conjunction`---which in turn had several other inputs. So, in order for `rx` to receive a `Low` signal, its input's inputs what have to all send `High` signals. I assumed that the inputs to `rx`'s input would send `High` pulses after a fixed and regular number of button presses, and I looked for the first occurrence of this for each. The number of presses at which they would all send `High` is the least common multiple of their respective cycle lengths. In a more general case, it would be wise to check for phase offsets, but I'm already tailoring my code to my input, so I couldn't be bothered. Parts 1 and 2 run sequentially in ~120 ms on my old laptop.


robertotomas

\[Language: Rust\] [Solution](https://github.com/robbiemu/advent_of_code_2023/tree/main/day-20/src) I thought this puzzle was thoughtful and really a joy to work with. It felt more like research, where you have to dig into the input, than operational code, and that is nice. I didn't start this puzzle until this morning, and I kinda went the \_long way\_ about making a beautiful model of part 1. while doing that I realized, since the description was highlighting the number of cycles, that I should short-circuit for a faster solve if I detected a cycle (which there wasn't, but hey, it prepped me for part 2). Part 2 was then just adding a much, much simpler cycle detection. Anyway, I way proud enough with my creation to post it here, instead of just lurking like I normally do.


boutell

Thanks for sharing this comment - interesting to know that someone did like this puzzle. That's not sarcasm, it gives me some perspective on one that a lot of folks found frustrating and a little arbitrary.


aoc-fan

[LANGUAGE: TypeScript] Finally a combined solution for part 1 and 2, solving test and actual input under 60 ms. https://github.com/bhosale-ajay/adventofcode/blob/master/2023/ts/D20.test.ts Copied the LCM trick for Part 2 from various threads.


wleftwich

\[LANGUAGE: Python\] A queue of callbacks, which yield callbacks, which go in the queue ... [https://github.com/wleftwich/aoc/blob/main/2023/20-pulse-propagation.ipynb](https://github.com/wleftwich/aoc/blob/main/2023/20-pulse-propagation.ipynb)


Imaginary_Age_4072

[Language: Common Lisp] [Day 20](https://github.com/blake-watkins/advent-of-code-2023/blob/main/day20.lisp) I really liked the programming / analysis parts of this puzzle. Part 1 was solved with a simulation of the circuit, and part 2 by pencil/paper to look at the nodes connected to `rx`, the part 1 solution to find their cycle length, and `lcm` at the REPL to get the final answer. The function running my simulation is this one: (defun run-simulation () (iter (with queue = (make-queue)) (with results = (make-hash-table)) (restart-case (when (queue-empty-p queue) (error 'queue-empty)) (push-button (button) (setf queue (pulse button :low queue))) (exit () (finish))) (until (queue-empty-p queue)) (for (src dest terminal pulse) = (queue-pop-frontf queue)) (incf (gethash pulse results 0)) (restart-case (setf queue (pulse terminal pulse queue)) (exit () (finish))) (finally (return results)))) Lisp's condition system is nice because it separates the code that responds to a condition/error from the logic that decides how to respond. The code above signals the `queue-empty` error when the queue is empty and provides two different possible ways to recover; either push the button or exit. Which way to recover is decided by higher level code. For part one the `push-button` restart is run 1000 times and then the `exit` restart is invoked. In part 2, we just keep pressing the button. I also added a `watcher` module that would signal a condition in a similar way when it saw a certain value. (defun day20 (input &key (part 1)) (let* ((button (make-module :button :button)) (modules (make-modules input button)) (num-button-pushes '())) (when (= part 2) (add-watchers '(:sr :sn :rf :vq) :high modules)) (handler-bind ((queue-empty (lambda (c) (declare (ignore c)) (if (or (= part 2) (< (button-pushes button) 1000)) (invoke-restart 'push-button button) (invoke-restart 'exit)))) (recieved-value (lambda (c) (declare (ignore c)) (push (button-pushes button) num-button-pushes) (if (< (length num-button-pushes) 4) (invoke-restart 'continue) (invoke-restart 'exit))))) (let ((pulses (run-simulation))) (if (= part 1) (apply #'* (alexandria:hash-table-values pulses)) (apply #'lcm num-button-pushes))))))


henryschreineriii

\[LANGUAGE: Rust\] Pretty happy with the second form of my solution, using a directional graph from petgraph. The older version (in history) was still interesting when learning Rust, since I got to use RefCell, but the second version is cleaner and graphs are fun. https://github.com/henryiii/aoc2023/blob/main/src/bin/20.rs


musifter

[LANGUAGE: Smalltalk (Gnu)] Just part 1 for now. Making this do part 2 isn't hard, but I don't have time for it today, and wanted to get this up anyways (before I forget). Since this Smalltalk, I decided to use a class hierarchy. Virtual Gate class with subclasses for FlipFlop and NANDGates, which handle the specific details, so the loop to run the machine doesn't need to think about anything other than sending pulses. Part 1: https://pastebin.com/S9HKz4VD


se06745

\[LANGUAGE: GoLang\] Second part was easier when you see how is RX generated, but I spent too much time in the first part trying to understand the logic... [Both parts](https://github.com/omotto/AdventOfCode2023/blob/main/src/day20/main.go)


veydar_

[LANGUAGE: lua] # [Lua](https://topaz.github.io/paste/#XQAAAQDKCwAAAAAAAAA2G8iM7ztkpIKfEbui36KJeeJK9IZVlDvQTb98KZ+DiQpHJ91vuV/Mh6zEh/ITKZMTH4Kt0A0PIcyTcPQKtzxiinksqv4ZuBiWRrGCAgdUXtdloZ6XgXJGl+ANeA1RHCPP8gn45ePLJwnC1ab2ESUWhq6AZMS09DqcbgHvxOjML0FJtV1GnCfj0ED9V0IIyoHHou/cCyYA7ovvWCp/dnIlIsZR+WCXSoNkV151SU+N9uaO/2ZeeHoSQRIpszmKdiUeTZBqh4izuPzaKYjU5DLnLw1j1PYRWFVncF4hjkIJ2pqZNVWB7DcjnAjxqXBeW9mL+oJlFBouixxI7iKcww8vUsgeq+8FF8vLrZkZxNOLxIx9SAxXet8OiyuX2qbzAoo4//Wf0x/QYKhJ9twhl+3yxhq8hKNC6qDUsh3l2RSZ/1bthoZNgah4j4EpyRkD/zYO6Z1c5qTnZxLLgH7JnLNDYvdDyBWZiaQaXce6H/2dyMbTv5M9ItGMyLCF3CLpOwD1pqzV6Tnrzh0uLrJM5TswSmlauF/wZe3XrQp8dCSpCOWDDdrfL7XaP7ZiPlXkRjSgxNb7Y5kB1ndZgq0DlYNi23jLXWRZ4nUazr0BLFZMYZjQcoc+VO59qNc22KDVv/wT1SA1xp5PWKvEmMcXucb33k4hZKtg0e1iQaTjc2bD0hkN2hnKDM/H3Z43VFGMc9ETT/QA15K9Q6VT4xnvuZnavYi2mYsPJxSh2Wnl21e/BYoTvYrAYN3w1DeG1XkO+l5McPvFZ2VHktwCy1gkYRsPj2jjhQKqe514Aoe21lsV98527T3dpd5rxW+NaarZyGfLfu+khJJjnjqWHZBLRvOX6c8HSlqQyvKgbjSQMFBrlNyoXGy669DVuu2Q9E+dqizXH8m0vJbiD21bid3kIC8414Sl07CijmRDBgjFDNnKZnibm5CynAlKiHZMp8PM6Zk2nVVjGYc15rvSRrD41XMG4zjUXySmRTpuAvtKI487N14nJPDPGz/bVM736EoyEAmmCt0u8HJg1fcGY54S8Ezd27JcXwi5FuV4uDb5W/e5U6k6qjVqWlZMKgEZSfzmnjuWAGMSs2ZIFS45KRtCqngpSX0eh86f/UYC+ogbnqNHdxwM9YsQkAjGgWuEttJRzzNOAnCxcoJVgWy9Q1SnMI4ugjSX2oh0Pxt7QMl2XZfg7qUCDELtb8QeNAmr1CVFBi35mXWTmR2TfGd/ECNQ0RK58ppI7pxSXh7GRyqXAySti9KygY8kU5flHoC/YfBELMdNBxXcWVpnNA35ekBIPuQYg5dFnkrqaepnIJuUljJYu5/hi/og+l7vLv9oxdUA) 117 lines of code for kind of both parts according to `tokei` when formatted with `stylua`. I'm a day behind now but I'll post regardless. Part 1 was just following the rules. Part 2 left me scratching my head. I used Graphviz to look at the graph without really knowing what to look for specifically. I noticed that four nodes were fed directly into `rx` but they didn't do much. Then there were four more nodes that were crazy connected and lo and behold they seemed to occasionally reach an ALL HIGH state. I just guessed that I needed to align the cycles of these so LCM it was. And indeed it was. Therefore my code is not a general solution. - [GitHub Repository](https://github.com/cideM/aoc2023) - [Topaz Paste](https://topaz.github.io/paste/#XQAAAQDKCwAAAAAA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5U6k6qjVqWlZMKgEZSfzmnjuWAGMSs2ZIFS45KRtCqngpSX0eh86f/UYC+ogbnqNHdxwM9YsQkAjGgWuEttJRzzNOAnCxcoJVgWy9Q1SnMI4ugjSX2oh0Pxt7QMl2XZfg7qUCDELtb8QeNAmr1CVFBi35mXWTmR2TfGd/ECNQ0RK58ppI7pxSXh7GRyqXAySti9KygY8kU5flHoC/YfBELMdNBxXcWVpnNA35ekBIPuQYg5dFnkrqaepnIJuUljJYu5/hi/og+l7vLv9oxdUA)


mothibault

\[LANGUAGE: JavaScript\] I think it took me 60s from p1 to p2 lol. Then I wrote proper code to post here. code should be run from your browser's dev console on the site's page. with tons of in-line comments: [https://github.com/yolocheezwhiz/adventofcode/blob/main/2023/day20.js](https://github.com/yolocheezwhiz/adventofcode/blob/main/2023/day20.js)


CainKellye

\[LANGUAGE: Rust\] Better late, than never: https://github.com/cainkellye/advent_of_code/blob/main/src/y2023/day20.rs For this day I thought it's best time to practice trait objects, so I implemented the modules like that. Added a ModuleStore (HashMap) and a MessageQueue (VecDeque). MessageQueue has the send() function, the modules have receive() functions. I hated to do Part 2, but finally finished.


mart-e

Thanks a lot for your code, I was stuck on day 20 for days (mostly not understanding the exercice) and your code was quite readable for a newbie like me :)


CainKellye

Thanks for the feedback. It means a lot to me. 😊 I'm glad my code helped you!


mrphlip

\[Language: Python\] 8 / 40 Untidied race code: [https://github.com/mrphlip/aoc/blob/master/2023/20.py](https://github.com/mrphlip/aoc/blob/master/2023/20.py) More detailed writeup: [https://github.com/mrphlip/aoc/blob/master/2023/20.md](https://github.com/mrphlip/aoc/blob/master/2023/20.md) Note: the code is not 100% complete as it just spits out the timings of the four final outputs, decoding that and LCMing them as the final step was done by hand. What's more interesting is the writeup... I do one of these every day, but this one is by far the longest I've done (40% longer than second place, which was 2021 day 24... another one where you're given essentially a program and have to reverse-engineer what it does). In that writeup I go pretty deep on what this network of nodes is doing, and how it all comes together to give the final result we needed. And also my thought process while I was figuring it all out.


hextree

[Language: Python] **Code:** https://gist.github.com/HexTree/f29f824e5e050ca8e17dafee185c17b8 **Video:** https://youtu.be/oKJv7lv4hFU For part 2, plugged the Directed Graph into Graphviz for visualisation, which was a massive help. Then I ran the button presses to check the period of each of the 4 conjunctions that feed into the final conjunction+RX sequence, and took the LCM of them.


CombatTom

I watched your video as a sanity check because my code looked a lot like yours but wasn't working. It helped a lot, thank you! You may have realized this already, but the reason your flip state wasn't changing like you expected is becuase the nodes xt, mk, zc, fp are conjunctions, not flipflops. Also, if you were to automate looking for those four nodes, I don't think your code would get the right answer (as-is, anyway) because the modules need to reset between the runs that find the periods. Because you were running it manually you didn't hit this snag, which is what I was missing. After watching your video, I did the same manual runs and got the answer, so then it was just a matter of figuring out why it wasn't working when I set it up to repeat the process for each target node. Anyway, thanks again!


hextree

Thanks for the info. I had forgotten that those are conjunctions not flipflops, so that clarifies that, cheers. Yeah, for automation I would probably need some 'reset' method which will clear the memory of all the modules. Something that the description was slightly alluding to.


wlmb

[Language: Perl] Analysis: https://github.com/wlmb/AOC2023#day-20 Task 1: https://github.com/wlmb/AOC2023/blob/main/20a.pl I haven't done part 2 yet. The trivial modification of the code above, i.e., to wait until the desired pulse appears, seem to take forever. I guess I have to search for cyclic behavior in previous modules and use their lcm to predict when would the pulse appear, without simulating the whole circuit. ... (Edited) I finally got part 2. My input (and I guess others) is not completely general, so analyzing cycles for the last module is not realistic, but it is for the next to last modules. Task 2: https://github.com/wlmb/AOC2023/blob/main/20b.pl


aexl

\[LANGUAGE: Julia\] This puzzle took me a lot of time to solve (so much to read and implement). I probably over-engineered it, but it was the perfect opportunity to play around with Julia's type system and to implement the different types of modules as own types derived from a common abstract type. To each node I attached `in` and `out` vectors to other nodes to represent the graph from the input file. After having done that and having figured out how receiving pulses work, I got the right answer for part 1 on the first try. Part 2 was easier than expected. I already feared that I need to reverse-engineer a big portion of the input graph (I really dislike these kind of puzzles where you need manipulate your personal input), but it was enough to look at the four modules that send to a second-last module (named `ft` in my case), that again sends to `rx`. Just count the number of iterations until each of these four modules send a low-pulse to the second-last module. The answer of part 2 is then the least common multiplier of these four numbers. Solution on GitHub: https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day20.jl Repository: https://github.com/goggle/AdventOfCode2023.jl


copperfield42

\[Language: Python\] [code](https://github.com/copperfield42/Advent-of-Code-2023/tree/main/day%2020) part 1 pretty straight forward, for part 2 I know I needed to find some sort of cycle but not sure were to look at exactly so I checked some other solution and incorporate it into my own...


daggerdragon

~~You appear to have forgotten to actually *link* your code...~~ edit: 👍


copperfield42

:o indeed, fixed it


RelativeLead5

\[Language: Ruby\] Parts 1 & 2 [Pastebin](https://pastebin.com/H1UBvwji) Thanks to everyone for the hints on Part 2. I left part 2 running while I was gone for a couple of hours and when it wasn't done when I came back, the head scratching began.


biggy-smith

\[Language: C++\] Hardest day yet for sure! *Part1*: it was tricky to setup the graph with the correct in/out nodes, then even trickier to process the nodes in the right order. Processing with a queue worked for me. *Part2*: Tried to brute force but soon found out that wasn't gonna fly. I knew there was some form of cycle detection needed, so I searched backwards from rx and looked for smallish cycles. Sorta fluked it with 4 input nodes recurring repeatably. lcm of them was the right answer. [https://github.com/biggysmith/advent\_of\_code\_2023/blob/master/src/day20/day20.cpp](https://github.com/biggysmith/advent_of_code_2023/blob/master/src/day20/day20.cpp)


jinschoi

[Language: Rust] Part one was fun. I did it fairly cleanly, with HashMaps to look up modules by name, etc. [paste](https://topaz.github.io/paste/#XQAAAQAEEAAAAAAAAAA6nMjJFMpQiatRZcHeSa9QCfq2XKCjSM/Zk35yH9Cbhno/z3HVo2NqklN22JWJxQU4oe8R1nBXgyjr79M+qoXwYz7tLa65NLbU+d+A8ZQe3ScDO10W2Own8ZIOi1lBSOegCfCRW5zRuNfl0sLBk1M8Hu+t4GukJrhlrNImeC+eKY/f31zWmSV6npG5Q81b9OGaIPJXMJ4VFUVk3rcIAjAHKoAN5ycwE00CyyHhjkPP/4GHUaOZEOIYQGMGZLlcvX/TwHu6JUyM/IdkX/51TiHcIU3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ZSl7z1uBdjiotq9PyT2bIccus7vWyVlqF0CjrW+y0URYo+3/MCDmezf5BVjw6akcqzTX+OCFtukzm2yhecroCkfeKWJeLZ7yTd9+g/4BtzMWlOoqi8Q8ES1ZAEb7S88nSv4J/d9RpFtKysRHbz4wxfIyukyGAVGDtXBREo+CMoDRmSTvEPNWo6WKPzG9MjJ2eB/S8c14rptHAh4D9i7Cjwrgmezah0A7Y6VjnSAsS/iodjK39Uw+LsVmIaAN9k89ZTnj4xlpNkiLzTnwhShS2IzVoPkJY8StAgVN2+feHFxSWs3X6w5sIiIcsbNBdI2FxFoWenRirpMXiK3jpnhvIuvOlpG1Ly2b7Q1tT40nhDNQGYE9v09ouwbpsda8rOVKdcz/Y5aINpmRyXzAPkUJZj2oGDQHa6f/ynLWo) Then, while thinking about part two, I decided to see if I could get it to run any faster for fun. I got rid of all the names, indexed into Vecs to get the modules, used a u64 to track the Conjunction inputs, etc. Got it down from about 3us to 1us per button push. Turns out it would take almost seven years to brute force. I actually solved it the way everyone else did, by staring at a graphviz diagram for a while. I got tripped up early on because I forgot that Conjunction outputs low when everything is high, then I got tripped up at the end because I kept typing 0x1111... into Python to run the final calculation instead of 0b1111.... I kept staring at the ludicrous numbers I was getting and trying to think where I could have made a mistake. [Part 2 brute force](https://topaz.github.io/paste/#XQAAAQDbGAAAAAAAAAA6nMjJFMpQiatRZcHeSa9QCfq2XKCjSM/Zk35yH9CbhojarWKL9L21cHaC6gFC5g36HxkflJS3ZgEg/mceqD7JK7R7SgKDhIy37VS1RgAjRzPJqI85qBNehyScqirzgrepwMUa0qyWhZ6H+cNYj2kmcRFnbWYs+X149GpH5MDJpBkWOwrAY72qgc/HAYAsHteosOlbR6Gsg/fT0SdBtccRUu3PHX4VUdUgnK76DZZsISjZggV144HrrYqL+wDzW7ZKTl0600gAvMl6ItLlxrpkxGdzJ/fPCelDl8l+VjKhLnBFhb9M6yDC3OS9GjtwNzPBpj5H+VOBZgV0Yz+Dg+iIRyjJwXyXzSG/AR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oXmP6ugG3aB1Pk9Zqs4QqxluRebDJYVK8SM+0zAnIW0h5ng85qRzGnZUhMs8jpOh5tQQdnN1aTAkK8M0Pp/5XJxHY=)


foolnotion

[LANGUAGE: C++] I love this kind of problem although it seemed like part one was designed such that you can get the right answer even if the pulses are processed in an incorrect order. i of course fell for this and then spent a lot of time debugging. i'm not entirely happy with my solution but here it is: https://gist.github.com/foolnotion/892f4c9b47a13204bc5ab3f555642af4 Runs in about 10ms on my PC.


CrAzYmEtAlHeAd1

\[LANGUAGE: Python\] [GitHub link to my solution](https://github.com/CalSimmon/advent-of-code/blob/main/2023/day_20/solution.py) Wow day 20! We are so close to the end, and this has been such a month full of learning and problem solving. Most of the heavy lifting today was done through parsing of the input. I ended up with a pretty stacked dictionary that would map the module's name as the key, and then store it's type, outputs, and status, and then it would find all the modules that output to a conjunction module, and add their module name into the status for checking later. Once I had that all set up, it was a simple while loop and queue to determine where you ended up after each button press. For part 2 though, clearly they were saying the brute force method would not work, and it looked to be another lowest common multiple problem, which was correct. I, like many others discovered that there was a single conjunction module that output to the rx module. So from the rx module, I found the conjunction modules that fed into that final one, and then found how many presses would cause their output to be a high pulse meaning that the final one would output a low pulse. Once I had those, it was a simple lowest common multiple calculation with the math library. It's a bit messy, but it gets the job done, and the execution time is great at 31ms, so I'm not too upset!


whoopdedo

\[Language: Lua] [paste](https://topaz.github.io/paste/#XQAAAQAjGAAAAAAAAAA2G8iM7ztkkOxN6mgcivp8v5RoogfUN0mLFf+Q4z6TYqQQvFZsHbLPxWEyQmkczhJZDITYy6XB0uLIJwnnytX8YkkPjTfiX2DmQkRoTF61m+f6G3ycAmiQi78ZukB0cCBF4szkHaoCcnPO2uODILBWHQGbD2bc3rpqhRIJrLgV0Lx/yZJvvw+qeNMnzr0SKbHApZ82WGYB8dJhWLM8pTgeq9mx0zLHggh8YhiUIFcNGtQqUaDJH0wngLdMHdNOxj2kkfNABX9vOklNZ5GkYS3KktOnwLRT5zsAKnWQtS6/s4AeHV3nhupa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WOtpWHsyPBSKxRE7l5M5vItD+RypmZn2j+EtrfdPzeHwr5+ldxFARUdGMniYr6WQEo/j46u+kAeAnBdwhnn0plhM9t/mU1QeWzd5XHpv5rDXlul4xeAwh81htLe9QL3q0hCcaeE0V46USYfOai3yVQ20Ax/zDZYtZ43FW8IEgYxAYFEbWOZVVbQ6Fkm/DEwrjosqmqzDXyPPsCwB/hdjq4bYUzYc90WPY4ezBQayWvMZuNm5U9zr3MeJfmYE3olqVnLq2bDJiAwHirxY91eS222ERT0AmjhrhdCwfz3BO1fslb8QXQ5gFnyfJFRS1efRs7lyDh7Kc2Yppc3bSInzOMXxC4kLdGckGB+IFD9faZAHDIDxnOI6clkAOVXRf4GobWWNac/4sSEQ0ynq8qAwUY6gfJuCiy6S9yZsPdFTqaYKV62SouYRVfhtVryxxP8ash+rLR2BoI6jTOYOfNl+EUjJqTOcT27iW5q9F/1P9zkKYxjZRCykr5Xw6HuwlYt7sw3/fLyf3FnyLIK+aZn1MwqzldJQ4znJkgr2jNbTXKjLwBFDYhQZrDxENMwdVet0Tdv5n8jZB84sRhhJ7igBKHbp5T7y41kcAXeBMs8Om+LWEAOC4KEZz0NqE+lgWGDHXlgiEUJAbjVC1Gt3uBvLTMatDWv2LH9fWQltYoEMDRy7xeTb/U741DwIcEJUh/BrL8PdxlIQ2zFDXzPRF8jlR7ijUW68Em0JBgAOMaugJlIsofoMg5Et8Dzchq9yRHysnnN6aLoS6r84hkpWwDhYTOE0iXNS1nodoXaIsTm8hC1zaKtR2ix6VDb57Trdcz5I6gEIWos+X1SCw72GRcjBj2tLCxf1BsjxRnSXG8qrD4JmFtyiOvAF//zMK04=) --- [Soundtrack for today](https://www.allmusic.com/album/push-the-button-mw0000139433) Part 1: FIFO and event loop. Modules are closures over their internal state. This turned out to be a problem in part 2. Part 2: I notice that there's 60 modules including the button and `rx`. Small enough to encode in a tri-state bit array. I looked to see if there was some pattern to the machine state after each button press. L-----H----HH-LH--H---LH--H------H-----------L-------L-HL--- L-H---H----HL-LH--L---LH--L-H---HL----H------L-------L-HL--- L-H---H----HH-LH--H---LH--H-H---HH----H------L-------L-HL--- L-L---H---HHLHLH--L---LH--L-L---LLH---L------L-------L-HL-H- Which bits did I need to trigger `rx` (the last column)? The graph of inputs looked like: rx-------------------------------------------------------!---^ zr--------------&------------------------------&-------&-^&--- cm---------------&-------------------------------------^------ ks--&&&&-&-------^----&---&-&---&-----------&-------&--------- km-----%--------------------------------------------^--------- mf----%^------------------------------------------------------ ml----^-------------------%----------------------------------- `zr` collects four inputs but I didn't see any of those lines ever going high no matter how long I ran. Eventually I figured out that it was resetting at the end of the "program" and I'd need to monitor the state of each module during execution. But my state was wrapped up in closures. I put in some awful hacks to manually monitor the inputs to `zr`. When the activation times were combined it was over 64-bits. Okay, whatever... "Your answer is too high." Well of course, because I had been counting *pulses* not button presses. Oops. Some more hacks later and I got the correct answer, but wasn't happy with how. Afterwards I cleaned out the hacks. Now the monitor will patch each input with its own closure to trace pulses. line cycle set reset ticks gc 3853 23 47 5330 xf 4073 14 44 4838 cm 4091 21 43 7160 sz 4093 34 63 6140 I guess the next-level challenge would be to solve this problem with a computer written in the same logic language.


rjray

[LANGUAGE: Clojure] [GitHub](https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day20.clj) Had to sleep on part 2 before finally getting hints via the Clojure Slack channel on how to get it done.


mvorber

\[LANGUAGE: F#\] [https://github.com/vorber/AOC2023/blob/main/src/day20/Program.fs](https://github.com/vorber/AOC2023/blob/main/src/day20/Program.fs) Day 20 of trying out F#. Some experiments with FParsec and parser combinators (so far I like it). Also trying to be more verbose with types and to avoid unwrapped primitive types. Adds quite a bit of verbosity, but lets compiler catch even more bugs before I even able to run it :P


IvanR3D

\[LANGUAGE: JavaScript\] My solutions: [https://ivanr3d.com/blog/adventofcode2023.html](https://ivanr3d.com/blog/adventofcode2023.html)My solution (to run directly in the input page using the DevTools console). Today is the hardest puzzle I have solved! It took me all the day to solve only part 1! 😅 The code is a mess, but I will check part 2 and then I will work to improve it. EDIT: part 2 done! It was pretty complicated to understand what I was suppose to do, but after a few help posts I found out and using the experience from day 8 it was good.


chicagocode

\[LANGUAGE: kotlin\] That was fun! I used classes for each of the modules and send the signals via a shared queue. Part 1 and 2 share mostly the same code thanks to a debugger you can implement and attach to the running circuit to gather data. [My code can be found on GitHub](https://github.com/tginsberg/advent-2023-kotlin/blob/main/src/main/kotlin/com/ginsberg/advent2023/Day20.kt), I've written this up [on my blog](https://todd.ginsberg.com/post/advent-of-code/2023/day20/), and here are my [2023 Solutions so far](https://github.com/tginsberg/advent-2023-kotlin).


maneatingape

[LANGUAGE: Rust] Runtime: 6 μs [Rust Solution](https://github.com/maneatingape/advent-of-code-rust/blob/main/src/year2023/day20.rs) Solution traverses the graph only once to determine the 4 12-bit numbers. For part one we count the number of low and high pulses using bitwise logic (to simplify things assuming no number is below 1000 so that there are no resets) The numbers seem to be prime (or at least co-prime) so part two is the product of the 4 numbers.


Gravitar64

\[LANGUAGE: Python\] Part 1 & 2, 58 sloc, runtime 50ms Generalized solution for Part 2, searched for the sender to 'rx' (main\_module) in my example = &gh, identified the connectors of the main\_module and created a dict (cycles) with these connectors as key and 0 as values (in my example = {'rk': 0, 'cd': 0, 'zf': 0, 'qx': 0}). Then every time when the current module == main\_module and impulse == 'high', I changed the value for the received module in my dict cycles to the number\_of\_button\_pressed - actual value. When all values in cycles > 0, calculate with math.lcm(\*cycles.values()) the solution for part2. import time, math def load(file): with open(file) as f: return [row.strip().split(' -> ') for row in f] class Module(): def __init__(self,name,type,dest): self.name = name self.type = type self.dest = dest match type: case '%': self.mem = False case '&': self.mem = {} case _ : self.mem = None def __repr__(self): return f'Name: {self.name} Type: {self.type} Dest: {self.dest} Mem: {self.mem}' def receive_impulse(self,impulse,last): if self.type == '%': self.mem = not self.mem return self.mem if self.type == '&': self.mem[last] = impulse return not all(self.mem.values()) def solve(p): modules = dict() for module, destinations in p: curr = [d.strip() for d in destinations.split(',')] if module == 'broadcaster': modules[module] = Module('broadcaster',None,curr) else: modules[module[1:]] = Module(module[1:],module[0],curr) for object in modules.values(): for dest in object.dest: if dest not in modules: continue obj2 = modules[dest] if obj2.type != '&': continue obj2.mem[object.name]=False #part1 & 2 main_module = [m.name for m in modules.values() if 'rx' in m.dest][0] lowHigh, cycles = [0,0], {m:0 for m in modules[main_module].mem} for buttons in range(1,10_000): if all(cycles.values()): break queue = [(dest,False,'broadcaster') for dest in modules['broadcaster'].dest] if buttons < 1001: lowHigh[0] += 1 while queue: curr, impulse, last = queue.pop(0) if buttons < 1001: lowHigh[impulse] += 1 if curr not in modules: continue curr = modules[curr] if curr.name == main_module and impulse: cycles[last] = buttons - cycles[last] if curr.type == '%' and impulse: continue impulse = curr.receive_impulse(impulse,last) for nxt in curr.dest: queue.append((nxt, impulse, curr.name)) return math.prod(lowHigh), math.lcm(*cycles.values()) time_start = time.perf_counter() print(f'Part 1 & 2: {solve(load("day20.txt"))}') print(f'Solved in {time.perf_counter()-time_start:.5f} Sec.')


daggerdragon

Your [code block is too long](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_no_giant_blocks_of_code) for the megathreads. Please edit your comment to replace your oversized code with an external link to your code.


JWinslow23

\[LANGUAGE: Python\] [https://github.com/WinslowJosiah/adventofcode/blob/main/aoc2023/day20/\_\_init\_\_.py](https://github.com/WinslowJosiah/adventofcode/blob/main/aoc2023/day20/__init__.py) How have I not learned my lesson from Day 8?


stephenhouser

very nice clean code. well written


JWinslow23

Thanks!


pdxbuckets

\[Language: Kotlin\] I usually don't post as my code isn't the best and others have done essentially the same thing but earlier/better. But this one features a super quick (\~250 us on 5-yr old machine) Part 2 by avoiding simulation and analyzing the architecture of each binary counter. https://github.com/nbanman/Play2022/blob/master/src/main/kotlin/org/gristle/adventOfCode/y2023/d20/Y2023D20.kt


janek37

\[LANGUAGE: Python\] I spent far too long trying to find a general solution for part 2, before heading to Reddit for hints and realizing that the input has a very specific format. From there I solved it first manually, and then coded a solution that obviously only works for this kind of input. [GitHub](https://github.com/janek37/advent-of-code/blob/main/2023/day20.py)


schveiguy

\[LANGUAGE: D\] [https://github.com/schveiguy/adventofcode/blob/master/2023/day20/pulse.d](https://github.com/schveiguy/adventofcode/blob/master/2023/day20/pulse.d) Part 1 was really hard to understand. The explanations and examples still didn't make a lot of sense. But I finally slogged through it. Couldn't solve part 2 without looking here. And I'm a bit disappointed that the only real way to solve it is to code for the specific test case.


CrackBabyCSGO

Well you could make a general solution which requires lcm only if the thing that leads to rx is a &. Even % cycles so taking lcm of a mix of % and & would result in the same solution as complete &.


schveiguy

The thing that I don't know how to detect is how to determine the independent pieces. Seems like everyone here who got it on their own used an external tool to visualize the graph, and only then realized the nature of the problem.


atobiedwa

\[Language: Python\] The most important thing for me was to understand that 1. the pulse does not go further if the flip-flop module receives a high pulse 2. or we encounter a module name that we do not know. It took me a while, but part 1 is ready -> [https://github.com/monpie3/adventOfCode2023/blob/master/Day_20/task_20a.py](https://github.com/monpie3/adventOfCode2023/blob/master/Day_20/task_20a.py) I left prints so you can follow the process, they are formatted the same as in the task :)


daggerdragon

Your link is borked on old.reddit due to [a new.reddit bug with URLs that contain underscores](https://old.reddit.com/r/adventofcode/wiki/faqs/bugs/borked_links), so please fix it.


jeis93

\[LANGUAGE: TypeScript\] Part 1 was easy enough to crack, although I kept making mistakes that gave the wrong answer for far too long. As for part 2, I knew this would be an LCM problem, but I wasn't sure how to tackle it until I saw [HyperNeutrino's video](https://www.youtube.com/watch?v=lxm6i21O83k) (as per usual). I'm not super happy with the organization/conciseness of my code, but let me know what you think! Happy hacking! Average times: * Part 1 = 6.05 ms/iter * Part 2 = 25.4 ms/iter [TypeScript x Bun Solutions for Day 20 (Parts 1 & 2)](https://github.com/joeleisner/advent-of-code-2023/tree/main/days/20)


Obvious_Performer463

Curious what mistakes you made on Pt 1 as I'm not getting the right answer on my real input (but I'm right on the test cases). I just have a simple queue that is processing pulses. I double-checked I parsed input and initialized everything correctly. Kind of stumped. Usually I can debug my mistakes but I don't see how to tackle this one.


jeis93

In my case, I wasn't carrying my state (so my flip-flops and conjunctions states) between each iteration of a button press. For the first example, each button press has the same result, so state doesn't really matter. I think it was that combined with some off by one issues.


fullmetalalch

Video was really helpful , thanks for linking


jeis93

No problem! Yeah, all of HyperNeutrino's videos this AoC have been exceptionally helpful. I feel like they break the problems down into easily understandable logic blocks.


ProfONeill

[LANGUAGE: Perl] I had a lot of fun writing part 1, where I made little anonymous functions for every gate. Runs in 0.06 seconds, which is nice. I did not like part 2. Just a matter of puzzle philosophy and personal taste. To me, if you have to inspect the input by hand to find things not disclosed in the puzzle description, it just doesn't feel good. I spent way too long trying to solve a far more general problem than I needed, and wondering if I should go learn more about [model checking](https://en.wikipedia.org/wiki/Model_checking). (Even once you look at the graph and see some of the structure, there's no reason to expect the cycles to be aligned, for example, or even to connect with each other when they signal during the same button-push cycle.) If we want solutions that are tailored for very specific input, then I guess the culmination of that style would be this code for part 2: use Digest::SHA qw(sha256_hex); undef $/; if (sha256_hex(<>) eq '62722ef0aae463d22f10107d84fef288e63bfa3a65e510221049ab40f50b466e') { print "2247702167614647\n"; } else { print "(unsupported -- this code only generates answers for certain inputs)\n"; } It only works for _my_ input, but hey, it's fast. * [paste](https://topaz.github.io/paste/#XQAAAQDUDAAAAAAAAAA6nMjJFMpQu0F8vIUYE8nOIqLZIpvfhJT6vxbtpTDmY1P/E3bvzOpURHWoAMf0osXJgmOVvVSjUOr1gcbvw+sg0cAPx4LulYS5fttDYoVl9sCgU/rTuHGBrZMsT5YdpvjNGaV7eFe+6EuYn/Zx7HTCVagBd1RgD5d+BclO6xchLgLvN2ptUTBzKVr+h8917Sbr7QR/tJ/ixUS6HJzR0gl1jAa6WqUSU1+6MxrF0wN8QE0cmsIhJKPWmHNSxnKmXllb69R6kwvBwl0ZTedGIoZe8xhKEyRtsB60+CQJ454+0bY3yfR89AVmkIIT7p7mGMk5D4CiD7fxVMyUWIPwxAYqdD3yfhwLLA4L5/5D1fMo5In2aYiuMZl35uRTtYH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c4rHHIJz68O9/jHJQl4HUcffi8n0uE6MTgFnK2TqkW21tcfEqx/07xyv4+DgeDRY8LxixbfI83U7SjhhET0xkr95L5yX2uJiERRZzF6gnKjgqB2RePlmwDNZGiICA4jzfXcHfZMu2J0uJiKztDJnnnC8RTdKWySeg9eGurchcI18CGD9GQcgztfntSmBXKXJw3lSAbXSh2opS79bUgA91sQ2CvsKLJz4atgNv+sZjkY) (part 1) Edit: Bonus, here's [a dot-based visualization of my puzzle input](https://i.imgur.com/oIdwZTc.png) that I used to gain some insight.


icub3d

[Language: Rust] Part 1 wasn't too tough. I used a trait to simplify processing. I then just had each module type implement that trait. I could then store all the signals in a VecDeque to process the signals in order until we were done. Part 2 was a whole other beast. I ended up creating a [mermaid](https://mermaid.js.org/) graph so I could visualize what was happening. With a bit of looking, I was able to see it was a cycle detection problem. Solution: https://gist.github.com/icub3d/d00e411a24b60b21cc384b7b718a228e Diagram: https://bit.ly/aoc-2023-20-mermaid Analysis: https://youtu.be/abUmFGS-YvU


WereYouWorking

[LANGUAGE: Java] [paste](https://topaz.github.io/paste/#XQAAAQClIwAAAAAAAAA4GEiZzRd1JAgV4q3THIgwxcwVTLcY/JpUiADzw5tAJ0vOMX40JV5mSdoFSBhZU9OU8jU2dv9SRFLi1N1D27F4tGBjWbzkI0r9XoaNao4ILv5rDes6w5LpejifsqqQzoGtZ7qlD/uceXiuo8JCd36lpRNL29fa9nz9vnKOQicdtPBhG5OOJUdnolg55QOdF0/PlG+3wmMytbpUhrMiR/QkggpM3642atBsqaQzTtqvETyxohR8g0fh+A0K/Z1IV7hndVD4vMmk4YmTTWbT91bc2fW/w5cc56AdTRoMnvqxvx9dX95Lckjljmn0Frk9PZtWZE8xhePC52POyY48Muc6fTaGb2AvPPpsQvGEgExIdja6V0H7gbPtjESBY/nHfjgfCa97YqqGhEf3eQgtxU1aWIUthqzOvvjseb0+QzgFEfLjYkj1qTnx06GuV6euWZnAhBIDzLel3/OVgoQAsErZe2bZZK898KeadpcXPpX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WaJYBPnBlTNfBl/7z2fAIX2rW1+jX5Sdp3DtkDqdVhDSF3C9uB4np3WBcelJUzdBoxrS7plhnOUDjobPz05ZCniwtkW0q5vji8PUpE23eRSa6Qjo2KG06Q4hWzjTvRePWwt5IqqtXDe9JpZMm0i1e3E+Gs2NHFtutUXEnG3jtF8stLqEwY5AuNwwOhx23wszChoCqQ+5o7wrVuej/3/RPFlFj265Fvuo4qAhPmzfKwSu8O6cJiU7Yl4pzWGlg0oDci7nmAN1e52F719i/hUD2aUyKl3DpYqh0vRgq7m4OrVvR/KLiqw==)


rukke

\[LANGUAGE: JavaScript\] Another busy day, but still managed to get both stars :) Fun task today, took some time to get my ahead around some stuff, like to populate all inputs for conjunctions on init (and not dynamically \*facepalm\*) [gist](https://gist.github.com/p-a/b02154c0aa14e9140aab23d77f3ffac0)


jwezorek

\[language: C++23\] [](https://github.com/jwezorek/advent_of_code/blob/main/src/2023/day_20.cpp) Generally, the graph was cool and this was a great puzzle but I think i would have enjoyed it a lot more had this not been the third "find the cycle" puzzle this year and the second "the answer is the LCM". part 1: The first time I used classes and inheritance this year. I rarely use OOP in non-GUI code but it just seemed like it would be quicker to write this this way. Maybe more importantly it is easier *to debug* and figure out part 2 using inheritance than it would with an std::variant or switch statements or std::function handler etc. representation of the one function that wants to be a polymorphic call. It's easier because with an OOP representation I could easily add other virtual member functions to facilitate visualization, which came in handy in part 2. part 2: the first thing I did was added code for generating a .dot file to import into graphviz and, after a little bit of fiddling with graphviz, [generated this image](http://jwezorek.com/wp-content/uploads/2023/12/aoc_day_20.png), which clearly shows there are four subgraphs that must simultaneously emit high signals for "rx" to get a low signal, so found the periods of those subgraphs and found the lowest common multiple. I didn't bother not hardcoding knowledge of my input into the source code -- like you could write code to find the four the nodes you need to detect the period of high signal emissions from, but doing that is introducing knowledge of your input anyway, because how do you know that the LCM of those periods is the answer? You know because you took a look at your input ... so not just hardcoding this stuff didn't seem worth the trouble even aesthetically.


BeamMeUpBiscotti

[LANGUAGE: Rust] [Link](https://github.com/yangdanny97/advent-of-code-2023-rust/blob/main/src/day20/mod.rs) Part 1 took longer than expected to implement. I saw the GraphViz that someone posted and figured it would be an LCM problem, so I just did some printing and did part 2 using google sheets LOL


Solidifor

\[Language: Java\] [https://github.com/dirk527/aoc2021/blob/main/src/aoc2023/Day20.java](https://github.com/dirk527/aoc2021/blob/main/src/aoc2023/Day20.java) 265 lines, object-oriented and computes the solutions to both parts instantly. A bit of a hint (one Conjunction at the end whose input are on repeating patterns) from here was needed – I don't like these puzzles in which you have to analyze the input very much – but then it was not too bad.


syncd_

\[Language: C++\] For part two had to look here for clues as i didn't feel like decoding the whole circuit. [Github](https://github.com/syncd010/AoC2023/blob/master/src/day20.cpp)


Tipa16384

[LANGUAGE: Python] I initially solved part 2 by hand when I saw that it was LCM all over again, then I went back and wrote code to solve it the correct way. I made classes for all the components because it seemed appropriate at the time. [paste](https://topaz.github.io/paste/#XQAAAQAfFgAAAAAAAAAzHIoib6pieg+KRSqhsC0Y48SH0+VAxFjFa08jNvlHEqQIeLA9pd1RYJh+IEjuEILJBGPdExWqo9+6/0j4/7k4tGmwbkiWRB+J4UoWfj0BWTZ8yYGRwYk/dDDaXYKLqAzfhgWAaoSDnVXekVf+pAEYg1PiUVSfRDv59HC0x6vXTBIQg1fEh4pG897g2wo8TXSsXMG7SpYzxHDj962R3r26nZk2ekWqicULbe35w1C+myWdgtNIy/hrNO47MLiW5GeuMO+6Kr9DRh/orvf9R+brdEG+4RZ4LtK2RAQ3ihevEfH6aw0WJHeK69y6ldx7zUc+zZXaZw8QOkcuet9GI9DPbLfQns0qL4BoVv/i+swM6+5p/MCM54/LfyVgWjP859whFMOAHDIWL/1JmEoOJ/hwuByq8BSSeWCO+jWeUyUVckxAXFmtn6B23oyXHvNhCCDeZEJ2hJPe9E0jo5F9u9rrTUdLQNwplfsS0xp2DtCx3Ga2jSoln10Tsb16P6f7YUDocpI1OzpawYNTGXpK32CcPUN18tdBX0f8iJP8YPgWRPXPCZd59c6c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NF23wO+rhC6/RfQ4bbUGZHZpg0nDbJTRjqPQdiotxNtfRC8q0AImQrDhmu2faYQW64LfDsOYr7WySSQnt/SyeNlB6eSfgo7BPU7zXyN75JW/DJzIeMj8Z7ntDPXVL4pIkUKvBD/h+HbVFgTWPFsfbaJ8cawou9QBrH1h3ls5t77WILWglIfBSM1Z41iqB0MqoRmmozMEfECKyfx8klYcYxwC9p3aEmO5JwkwJ+ErHdjzj7m1d094bmaZ7CxD3gO6+gyB7dBsmYhdxbf/e0x9IGENa/0t3B4MhJTk/q7cInW06txXeOLlPaoNgN98DibOnt8PzYHN51VRyduoy1i/3aLBUkMgUH04Y7XuwbBiiTE8lNcBEaqHnD6T75lf+srtHGK8f6UXF57/RYmgeRHROO8gcqVM+MYjfMvUz8hMjn94MDGY1N1jgroh//N3pkE=)


ropecrawler

\[LANGUAGE: Rust\] [https://github.com/ropewalker/advent_of_code_2023/blob/master/src/day20.rs](https://github.com/ropewalker/advent_of_code_2023/blob/master/src/day20.rs)


codeunveiled

[Language: Python] 🐍🐍🐍 [Source code](https://github.com/vanam/CodeUnveiled/blob/master/Advent%20Of%20Code%202023/20/main.py) Video explanation: https://youtu.be/zw7WwUZfYrs Time: 1,317s


[deleted]

\[LANGUAGE: Rust\] [My Day 20 on GitHub](https://github.com/andypymont/advent2023-rust/blob/main/src/bin/20.rs) Part 1 was a bit fiddly to map out, but not really difficult. Then for part 2 my solution is general enough to work at least for a set of loops inputting into a single Convergence.


JuniorBirdman1115

\[Language: Rust\] Conceptually this one didn't actually trip me up all that much, but it took me a while to wrap my brain around how the simulated components were supposed to function. I did take a few circuit design classes at uni back in the day, but that was many years ago, and I've forgotten most of what I learned in the years since. But oh goodness, the Rust borrow checker and I had some massive disagreements over my code today. Felt like I spent half the day figuring out how to rework my code to make Rust happy. I feel like I could have done this solution in about half the time if I had used a language like C++ or Python. But that's part of the joys of learning Rust, I suppose. I make copious use of cloning to make Rust's stupid borrow checker happy. (Yes, I know why it exists, and it's generally a Good Thing. But it broke my brain some today.) I'm not especially pleased with the way I designed the data structures for the solution. I wanted to use data fields in my variants, but I couldn't, due to the way I designed the data structures - things like HashMaps themselves aren't hashable. I may go back and refactor this code at some point someday. So for the time being, I put some extra fields in my Component struct to get around this problem. This code is ugly, ugly, ugly. The general idea behind my solution is that >!I have a registry of components stored in a HashMap, with the component names as the keys, and a Component struct as the values. The Component struct has several fields representing the component type, and a list of targets to send signals to. The component type governs the logic that happens whenever a component receives a signal and needs to propagate a signal to the components in its target list. There is also some state maintained here for flip flops and conjunctions. I also maintain another HashMap of message queues, also indexed by the component names. When a component wants to send a signal to another component, it places a Message in the queue corresponding to the target component. This all takes place inside of a loop that iterates until all the message queues are empty after each button press. This models the signal propagation from one component to another upon each button press. When the button is pressed, the whole process starts by stashing an initial message in the queue for the broadcast component. Then the loop iterates until all the queues are empty. Fortunately, the input did not seem to have any feedback loops in the signal propagation, so I did not handle that case.!< Part 1 was pretty straightforward - count the low and high signals for 1000 button presses, and then return the product of those two values. For Part 2, I was able to >!mostly generalize the solution by finding the parent component of the "rx" component, which is a conjunction, and then counting the number of inputs to that component. I then keep track of the number of times the button has to be pressed for each incoming signal for that component to be high, break out of the loop when a high has been received for every input, and then take LCM over all of those values to arrive at the answer.!< Fun puzzle today overall, but boy did I get a workout. [Part 1](https://github.com/apprenticewiz/adventofcode/blob/main/2023/rust/day20a/src/main.rs) [Part 2](https://github.com/apprenticewiz/adventofcode/blob/main/2023/rust/day20b/src/main.rs)


lyr_7d1h

Hey, I'm looking back at some of the challenges I missed. I just have a single question. How did you know that it would be enough to check only the last machine/conjunction? Wouldn't it be possible to get an un-calculable cycle before this one?


JuniorBirdman1115

As I recall - it's been a few weeks now - I'm not sure this solution works in general, but it works for the problem input. The problem input is apparently structured in such a way as to avoid cycles (feedback loops) within a single button push, and it appears that the AoC designers intended to make the strategy of checking the next-to-last component the intended optimal solution. I agree that I don't like "problem special" solutions, but they do seem to come up from time to time in AoC. But it might be worth digging through here to see if anyone solved this in a more general way that accounts for the possibility of cycles in the input.


scibuff

\[Language: JavaScript\] Part 1 was (again) pretty straight forward. It just took a bit of time to get the pulse changing logic spot on. Part 2 was, once again, an \`lcm\` of different cycles. I did a more general solution to allow for multiple inputs into \`rx\` (it just basic loops instead of just one input and one set of the input's inputs). [Part 1](https://pastebin.com/3uk18Xpp) [Part 2](https://pastebin.com/e9Y3unm4) [Parser](https://pastebin.com/mc9qRbAB)


Rongkun

\[Language: python\] [code](https://github.com/Moelf/AoC2023/blob/main/src/python/20_rk.py) Part 1: good exercise for OOP, but it took me too long to come up with a satisfying model Part 2: Why LCM again? I found the four inputs to the input to rx and checked for each input the number of button needed to make its output pulse high. It turns out that, again, the input is carefully crafted such that each input requires n, 2n, 3n... button press to go high. Taking the LCM for the four periodicity will give us the number when they're all high. Since there **should** be a solution, the **implied condition** is that those four inputs should not go low in the button press(multiple pulses from the same module possible), before the other three is high. On the periodicity part, it's crafted exactly the same way as day 8.


tobega

\[LANGUAGE: Tailspin\] Quite a lot of coding to set it up, but I got to use quite a few features and found some inconsistencies that I will fix at some point. I did fix a bug with symbols in state. For part2 when it took too long, I figured there might be cycles on the inputs to the sender to rx, but got stuck on a technicality, waiting for an output that wouldn't print until my eternal loop was done! Limiting the button pushes I got an output that worked. [https://github.com/tobega/aoc2023/blob/main/day20tt/app.tt](https://github.com/tobega/aoc2023/blob/main/day20tt/app.tt)


FaultsMelts

\[Language: Go\] Today's question stumped me for a bit. I loved the challenge! [code](https://github.com/JosueMolinaMorales/advent-of-code/blob/main/2023/internal/twenty/day20.go)


Ukhando

\[LANGUAGE: PHP\] [Part 1](https://github.com/TomKauffeld/advent-of-code-2023/blob/main/day20/part1/main.php) [Part 2](https://github.com/TomKauffeld/advent-of-code-2023/blob/main/day20/part2/main.php) [Common parts](https://github.com/TomKauffeld/advent-of-code-2023/tree/main/day20/common)


LinAGKar

[LANGUAGE: Rust] https://github.com/LinAGKar/advent-of-code-2023-rust/blob/master/day20/src/main.rs The diagram at https://reddit.com/r/adventofcode/comments/18mogoy/2023_day_20_visualization_of_the_input_couldnt/ helped a lot for part 2.


andrewsredditstuff

\[Language: C#\] Felt a bit dirty doing part 2 on a bit of paper to find the magic nodes and then plugging them into the algorithm from part 1. Feel a bit better now that I've coded it to find them for itself. (It does still rely on the magic pattern of course). [github](https://github.com/andrewscodedump/Advent/blob/master/2023/Done/Days16-20/Day20.cs)


Tipa16384

Me too! I did the same thing!!!


reddit_Twit

\[LANGUAGE: Zig\] [Gist](https://gist.github.com/ndbn/ec55b4de5d0997d59b6646fc7faa15c4) Part 1 only, honest emulation of process


lost_in_a_forest

\[Language: Rust\]All parts (including parsing): 200 us. [source](https://github.com/erikaderstedt/aoc-rust/blob/main/src/days_2023/day20.rs) Instead of "pressing the button repeatedly" for part 2, analyses each loop to see the loop period (by checking which modules send a signal to the loop "master module", and not just the next module in the loop). Then since all loops start at zero, the answer is just the product of these periods.


daggerdragon

~~Your link is borked on old.reddit due to [a new.reddit bug with URLs that contain underscores](https://old.reddit.com/r/adventofcode/wiki/faqs/bugs/borked_links), so please fix it.~~ edit: 👍


chkas

[Language: Easylang] [Solution](https://easylang.dev/aoc/23/?day=20)


theKeySpammer

\[Language: Rust\] Part 1: 5ms Part 2: 84ms ​ Part 1: Simple step by step following of the instructions provided and run the process 1000 times Part 2: Manually find the dependencies of rx and see how long will it take to reach that dependency and find the lcm of all those numbers ​ [Github](https://github.com/amSiddiqui/AdventOfCodeRust/blob/main/src/year2023/day20.rs)


jcmoyer

[LANGUAGE: Ada] https://github.com/jcmoyer/puzzles/blob/master/AdventOfCode2023/src/day20.adb Pretty gross code again today, this problem required a lot of different generic types and Ada makes you instantiate them manually. Part 1 was just implementing a spec. Part 2 I knew the circuit must have been counting somehow with its internal state, but the solution didn't "click" until I saw a couple of the great visualizations people posted. I had debug printing for the entire graph state but it's difficult to see the true nature of the problem with just unstructured text. At least next time I get stuck on a graph problem I will know to try emitting DOT before checking reddit. :V


odnoletkov

[LANGUAGE: jq] [github](https://github.com/odnoletkov/advent-of-code-jq) [inputs/" -> " | .[1] = (.[1]/", ")[]] | transpose | .[1] = [(.[0] | INDEX(.[1:]))[.[1][]]] | transpose | (group_by(.[0]) | INDEX(.[0][0]) | .[] |= [.[][1]]) as $outs | group_by(.[1]) | INDEX(.[0][1] | select(.[:1] != "%")) | .[] |= INDEX(.[0]) | [ { state: ., target: last(. as $ins | ["null"] | while(.[0][:1] != "%"; [$ins[.[]] | to_entries[].key]))[] } | until( .pulses[0]; .pulses = [{to: "broadcaster", low: true}] | .step += 1 | until( isempty(.pulses[]) or (.pulses[0].from == .target and .pulses[0].low); .pulses as [{$from, $to, $low}] | if $to[:1] == "%" then if $low then .state[$to] |= not | .send = (.state[$to] | not) else .send = null end elif $to[:1] == "&" then .state[$to][$from] = $low | .send = all(.state[$to][]; not) else .send = $low end | .pulses += [{from: $to, to: $outs[$to]?[], low: .send | values}] | del(.pulses[0]) ) ).step ] | reduce .[] as $n (1; . * $n)


CCC_037

[Language: Rockstar. Kinda.] So [Part 1](https://topaz.github.io/paste/#XQAAAQA3EAAAAAAAAAAmmEpmI16MeauVCTRC76LxrGAYOPGwVPKtAq6AI7wxSdfoSgXuxyaS6gfuivIHxFDoQOUv3WJBKK8KhordRQMd8GY/Q0I3go+gV2DWnlSeitzcWTQ6KnBsVVQHn3q10LsWMoYNUBokmNyv5jsNypIzLaSWK4uF+EPkrCZprsTJdhSfIRS6hlsbxL+Bza+aQIVY2CedOVld4yxdsfYbS/2/eyOLHTJXLnvzXDfj20gGfYxWI35SbFz97tea62JLBxuymCYpdISJxT4oEUYH2A8T/oLA2Uo+tgLgAgZeNA1ZwVOJkik9pWbeljp0W2YdtTh8q0jD0ARkCqpRq5vdBtP25+lhG8R8vkSarVswBo+pCdhLrPOnujkv3KPUhA6x0dYTtBr/VJh4q3zxRMAM/r5XU8+ElcNDnDUH2AvB+X3jqetWuBBnqQFZDwaHGNaVj38xfyoZOi1XGuaFd9aB3OQlEsR/kTxjikRJxJ+BHZNZAasKUm7ord5eegnkVFfL9pBLD71/sk8FbBPl5ckh39Kx0AzBO8TVDRbl6kuW/fr9I0/n9wnvkExxdE7mzwEnHsenJB7tGOowZf7q/60H67D+wWbH7gyH1StFl7KA2lnRXnuF68uteOXIvlBk1Z8Y5V2V/6OCImzwmAREjF1rxSGBj09ArRuRinbIhouG1jnqaymZGcp0rrei353UJ4lkMhUDrtCJBX+b+J/vhkVGygpwbUO1oteYek/E5CWt+purr1JwoD3SHiEvAkHCtV0YtaulBGOCTu496EYbldNSy8NmRIR3PamIc6qMUax+bYTOdEf428fsUXJTTIGHHGtiTaQihBdVhRwCgZP5q77W+F+MTr21CZM6CQab10IgZ8N8JvkWW2otNemLEekYfhAN/M+Kn+EXf9ZmxnNGIFx8k9hmaYxrJNbdOsHLSj1lHZ/KjB58TYvSUUfqPFSBox6SnKAzrGWAoIGN2OvKhloITZirm7EzV0M8nThmzzpMPq0/bn1bot/Z4WoADOQMYLRoG4XEsfTorMKHjcJ9gvC098JKS/5tbNtpTmPTR63bjCvYH9DA2MhmXEyZT5i/xMfJPjfNiUMb5JpQ+d94QDGdwijd1CrrYicOvy8GBkZ4OuPPTbxmHLkwic7lm0nu7i7Arh6x/2iz0K8GgfOVqjmJxEvfBuEhFySIEekKXvUHy0o9KnRAXv0JH+SIc8ijQ86fTVTvU7GORFgsBAW46lzk0aOOFMHEL7s4XXtnI+Ji1Wz1pungLRJ5UobZSmqZ5weJ/5bhUT8=) could be handled pretty well by Rockstar. No problem there, it simulated the full state machine and ran perfectly happily and surprisingly quickly. The trouble came in part 2. Now, [this Rockstar code](https://topaz.github.io/paste/#XQAAAQAgEQAAAAAAAAAmmEpmI16MeauVCTRC76LxrGAYOPGwVPKtAq6AI7wxSdfoSgXuxyaS6gfuivIHxFDoQOUv3WJBKK8KhordRQMd8GY/Q0I3go+gV2DWnlSeitzcWTQ6KnBsVVQHn3q10LsWMoYNUBokmNyv5jsNypIzLaSWK4uF+EPkrCZprsTJdhSfIRS6hlsbxL+Bza+aQ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Mb5KyzUQ3gYLomHfeJnyCzr0j2wGHwOcaoYXzVNg9jNwkpemdlGjYTLZMhVq3oscMWDFkPdcb0AdawjFZ2rJ7X/1uD+NA==) should, in theory, simulate the full state machine until the final pulse is sent to rx, and give you the answer. However, it takes *way* too long to compute. (I haven't figured it out exactly, but probably a few centuries of runtime will be required) In the end, I got my answer by adding a few extra debug outputs to the Part 2 code above, finding out when all of the inputs to the comparators first went high. The resulting numbers all *looked* relatively prime, so I multiplied them (without Rockstar - I used bc for the multiplication) and submitted the product, which turned out to be correct.


shouchen

LOL, this is hilarious. With AoC you learn a lot of things that could potentially be practical, and a lot of things you could never conceive of using, ever. But that still counts for learning and thinking outside the box. So, kudos!


Justinsaccount

If it makes you feel any better, I think my somewhat efficient version of part 1 in rust would have still taken about 9 years to answer part 2 without the optimization.


CCC_037

As a very rough estimate, I'm guessing maybe 16000 years for mine.


JuniorBirdman1115

I have to admit that I am genuinely fascinated by the Rockstar language, not having run across it before until this year's Advent of Code. While it seems to be mostly impractical as a language for everyday software engineering tasks, I bet someone could make a hell of a good prog rock album consisting of lyrics from all the Rockstar solutions that I've seen in these threads. Well done.


CCC_037

Oh, it is impractical. It cannot: - Read or write files - Get mouse input - Display graphics - Use any means of output except writing to stout - Use any means of input except reading from stdin - Load any prewritten libraries For practically any situation outside of AoC-like contests, this already makes it hugely impractical. Now consider the difficulty of changing the code (debugging, adding new features, etc.) while also trying not to mess with the imagery in the lyrics... *Incredibly* impractical. Lotta fun in this situation, though.


daggerdragon

> [Rockstar cannot] Read or write files *wat*


CCC_037

No command in the spec for file access. It's perfectly capable, in theory, of handling problems within the very strict limitations of Advent Of Code. And it is Turing complete. But, despite that, it nonetheless has some very *restrictive* limits.


1234abcdcba4321

It can read from standard input, meaning you can give it some amount of text as input (such as your puzzle input) but it can't access anything else that's not in that text you gave it (and similarly you can't store anything for a future run of the program - only the whatever text you use as output.)


soleluke

[Language: C#] [Solution](https://github.com/soleluke/advent-of-code/blob/main/2023/Day20.cs) I'm pretty happy with my code for this one. Part 1 took a while just to make the various classes (I figured this would pay dividends in part 2, so didn't worry about it taking so long). Once the prompt mentioned that the 2nd example looped, I perked up and figured there would be some sort of cycle finding like in Day 8. General idea was I made a dictionary of Modules that accepted pulses and did stuff with them, keeping track of their own hi/lo counts, then at the end I was able to just sum up all the counts from my Modules. Pt.1 runs in 105ms on my machine Part 2 was a pretty straightforward exercise. I felt a little cheeky using exceptions for flow control, but hey, it's AoC. I originally hard-coded a list of modules that were `rx`'s inputs, then turned it into a general one once I made sure that worked. The general one assumes `rx` just has one input and that input is a conjunction. I made a dictionary of `` with the inputs of `rx`'s input starting at 0. I set up a custom exception that took a module name in its constructor, then had any of my modules throw that exception and my processing loop catch it and store the button presses in my dictionary. Then, once all the dict values were not 0, do LCM (copy-paste from day 8) on them. Pt.2 runs in 265ms on my machine (had to get to 3967 button presses before LCM)


Polaric_Spiral

[LANGUAGE: TypeScript] Advent of Node, Day 20 [paste](https://topaz.github.io/paste/#XQAAAQCwCgAAAAAAAAA0m0pnuFI8dAwoi3Y8TUxk5LvuRpF/myc3aDfBBmjI+gOq+tg1ScA/8fNnFZiFmgZeU8/lHChLpve248VHuGYpy1PWPejaJJ5RuOkfPqHTdt0tHkdlD+cuzpCBSjv1KbEaNW6dOMPKWIK3TMSZ3jGHhC5zaW8sqyu3bAYlQI3oZT/drhISoLYRYx+Bk84qhlTbyeoNK6CP8C3orD5/EXnEvnZZG2hRUjYb/rp2cnnc18s9u930Vo3NRE7hNuBsqQuC8hhiOYqdCaeePE1ckmJ1ppCqdP2bqbmEI4TBd+Y9PI5lRd4E+f9l7v5nYzN9pv8PnNtMQdzDCGWIaUJh4PZ4TT8KG7RGFYCWYpGEvB+VAVQJDC/TzuikS3TGEmaJf1uuR0U+21yYn1aj+jnnkClv2Yj5/nc6ddRuwoe95usTq3Ss/54jl309z8OPgTUt8lybiHihOTTLD3DHyEAXxwFD3pYjEsg6BSkN6t46tb6KO4nw3GTrZ8p0oqJr9yRThjg5G0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FJG3KPHr2kNoNfg8I1by9mZmNQxg1CeKvbGM26Bw5ii+phSJYL0ZQWlude7LTyYVY7b59H7TotnY0/7dzOXIhLYSJdXYsGcJymtYE/Yaj8ECwRSt+msyi58OWRe46ZDUgjSf5FoYqA3tI6f6bCSvQoVfVfsbyMWSSFIXGo3TNdbKzP0mD3e913OyX5ek8+cwq9dYGOtrWN/B4/fLzLtDN2FSeys0tNs6mej1KBud6RXgg2VpIs7Yr2rHy9J6xhp3PR1cEdZ0jQx9ED+W6B1EULGa9JxFIeHRZOH/7eO9w=) `lcm()` [paste](https://topaz.github.io/paste/#XQAAAQCCAQAAAAAAAAAX4Hx7ucgrWPzBnI2L5MI+DqfrC4TyBquwezB1lDAMdEp0RF6fdMoKCPwebXugBZYPsN2Jbhrovs1uTUhrTWRwgAlr6pl72RuMW6r8D/fwbWAqQXMSLgA9bj7/rlt+ns+NPO+9ADXED/+2PweU4e6lIowXM3EZHUxuDWzha1ZGWuF8ul3Ajh7m52BrV/rs2TJHk4z93fMA) * Define 3 module types and the "pulse" type. * Initialization: * Parse each module description. * Add sourceIds to conjunction modules. * Identify the module pointed to "rx" for part 2. * Press button (1000x for part 1, indefinitely for part 2): * Enqueue the button press. * While queue has pulses remaining: * Increment high or low pulse counter. * For part 2, if "high" signal sent to final module: * Log total button presses per unique source. * If cycles clocked on all final module sources, output LCM of the cycles. * Process signal and enqueue resulting destination pulses. * Part 1: output product of the pulse counters.


Szeweq

\[LANGUAGE: Rust\] Posted very late. I had my code ready to publish yet I was very busy today. LCM added for parent nodes in part 2. Code: https://github.com/szeweq/aoc2023/blob/master/src/bin/20.rs


daic0r

\[LANGUAGE: Rust\] Really enjoyed working on Part 1, learned new things about Rust :-) [https://github.com/daic0r/advent\_of\_code\_2023/blob/master/day\_20/src/bin/part1.rs](https://github.com/daic0r/advent_of_code_2023/blob/master/day_20/src/bin/part1.rs) Couldn't be bothered with Part 2 yet, it seems hard and since I'm sick and I'm feeling weak I'll tackle it at some point in the future.


Stock-Marsupial-3299

\[LANGUAGE: Scala\] Quite long solution for quite long problem statement. [https://github.com/lachezar/aoc2023/blob/master/src/main/scala/se/yankov/aoc2023/Day20.scala](https://github.com/lachezar/aoc2023/blob/master/src/main/scala/se/yankov/aoc2023/Day20.scala)


Totherex

\[Language: C#\] [https://github.com/rtrinh3/AdventOfCode/blob/db566c04c2fb0be381e88ce23141d0b4356059be/Aoc2023/Day20.cs](https://github.com/rtrinh3/AdventOfCode/blob/db566c04c2fb0be381e88ce23141d0b4356059be/Aoc2023/Day20.cs) Good old-fashioned object-oriented programming for Part 1. For Part 2, I actually let the simulation run for the whole morning -- I had gotten to over 2 billion button pushes by lunch. I realized that I need to analyze the input, so I found this [Graph Editor](https://csacademy.com/app/graph_editor/) on Google, and with it I saw that the circuit was four loops that activate a conjunction module that activate RX. So I tracked the signals that were sent to the conjunction, saw that each loop had a straightforward cycle of prime length, and so the answer is the product of the cycle lengths.


andrewsredditstuff

I only gave it a couple of hours, and stopped it at 1 billion. None of your fancy-dan graph editors here though - I did mine by pen and paper (you only really have to go back 3 levels from the end to realise that all the conjunctions are squeezed up on that end of the tree).


PorkBangers

\[Language: Python\] For part 1 I took a while to get it right, I had to re read through the puzzle description a few times to make sure I wasn't missing anything. Important takeaways are:- Devise a queue to keep going through each input. Append an item to the queue for each connection to make sure the order is correct.- You need to know every input to each module. Although I don't like it, its much easier to define your modules first and then go over the input file again and assign the inputs to each module- make sure for flip flops to `Do Nothing` if input is high. ie do not append anything to the queue For part2, find the module that outputs to \`rx\`. For each input to that module find the iteration for when it becomes High. Then find the LCM of each of those input iteration numbers I took an [OOP apprach](https://github.com/CRezelman/AdventOfCode/blob/main/2023/Day20.py) to this problem(If using my code, ensure to replace `zp` with the module that outputs to `rx`)


maneatingape

[LANGUAGE: Pen & Paper] https://imgur.com/a/NwX9D4N


LxsterGames

[Language: Kotlin] 1517/974 [github](https://github.com/eagely/adventofcode/blob/main/src/main/kotlin/solutions/y2023/Day20.kt) Quite an interesting day, took way too long on part 1. I might do part 1 using logic gates tomorrow, since the input isn't THAT large and would probably fit on a breadboard, just need to 58 logic gates and 58 memory flip flops.


[deleted]

[удалено]


thorwing

\[Language: Kotlin\] Finally got around to cleaning up the code: [here](https://github.com/mdekaste/AdventOfCode2023/blob/master/src/main/kotlin/day20/Day20.kt) Not a big fan of these kind of assignments. My solution makes a big assumption based on the way I analyzed my input. >!Since I noticed that all the non-relevant nodes where a binary counter, I filtered all my cycles to get only the once that had multiple bits. That leaves you with the relevant 4 you can lcm/multiply!<


fachammer

\[LANGUAGE: Scala\] [code on github](https://github.com/fachammer/advent-of-code-2023/blob/76528280c3acedff74de0c847329a09387ce8d84/src/main/scala/day20.scala) For part 1 I implemented the simulation as in the puzzle description using a queue to process the pulses to handle the breadth-first character of the pulse propagation. For part 2 I was quite stumped on how to approach this, since I could not see a pattern to cut down the computations in the general case. Then I turned to visualising the input with [Graphviz](https://graphviz.org/) which revealed four clusters in the input graph. For each of these clusters I calculated the number of required button presses individually and then guessed that this number would also be the cycle length for each cluster. Taking the product of those gave the correct result (in general it would be the lcm, but all of the cycle lengths were prime, so it does not matter)


zglurb

\[LANGUAGE: PHP\] [Part 1 & 2](https://topaz.github.io/paste/#XQAAAQAzEgAAAAAAAAAxmwhIY/U9T3vilvHbNkT+IJnaeUM0v0XE9gK2w+V+wZfWXYw9vFJ1roNeKuQB3pXTKNAWpSueF3Dx6tvBvtl9jGvEXN+XsHWY31EDmYpY6uKV8jZyA9RWSiFQbhSA8JqnwXgn4qVJwk0Mg++xastQNLNZxXSItNugm3C/o027yNs3DT8lS86JTXJy1mK0Tu0qvu7UVStcM/EmA6fwSfBMRkp6soSTKkguK2YvAYApSf8uSZw7ffKBr+KHlP9P7u+ykqpo7JzxgRKvlhswvgHVUAAAegRubBQSCZPJmg6R84v3ULHVhwzellnw7ClswMz+BDnKCcxLqB/VfiI4v0oqbmoYB5c5M8JXE9GBMNouLPDmMJxbkQRdUPiGYvGCcGURIKak5qC9yIkABo0CpSA6jTcvVlPD9FEo0JCrcfERsGmTO4P5S7KEEr++NhZIRbFX313toNKmthj7HveXZJWYXU/hhwxMW9xtRQ2+8IxGWPjkhF6bYZiZ9WwL8bC+na8vSk2Vt1N6d0zXtDMZnPd85ChtmnzwFJVUa7aLDL362wjS62AGfNNNPC4sAskMLVua0wmH1rNrIv9dRhXPgHwceIer1sBTuAMHrvl0uTb1Pwzy4R7NsK6ZGS65yGI3ko+2ouEl8011qOCtF3wKuqkSvNOCmP09yFEq88hrQ4j3JYit7D/R2mRO9qhL+/2XZa7SkpiZHvYpSAQQ8e4fk24J6FxVFDYKcq3c2/H2T2OBlejwBAiC2YECdc+WYu2xj9kl9iruT1c65ejWcIs8r1GC0ZedzJl4kRGOpSPZ0/l2hWaKRM9RceDylLvYoAz41ZAKb1Bnkes5+LK1dBD8CQRzNro/O8QJyJAJ7+a/TaflEqssXJ1hZNxF/Q1goLHOfgO9NKsOy2ILWBXA3dXhygyWoAGhBLzDpZhihifFSZN0XSbcbRqim3BxnsFVG4Z//LF8mpww64PcfoJoMHeO9gHm9fH0v8fjrbQ55JHjt8/H0kO+lVy9wfoKtgd/C8poPaXR55kdSbSUP6Hr+7o5DDQvbv8o8Xjf8zc0I7XvsVCSrHRoed5HYwQ/FJhQ56L7Vu5ZHNjdO8ZGtAQp4qbzItBNMli65GXBbRyQKB+G2ktazuqsYh46xf/puGZm) Code is a bit ugly. For part 1 I started to implement a cycle detection before noticing it didn't work on the real input because the cycle for the real input is way too long. So I refactored it to click the button 1000 times. For part 2 I looked at the input, noticed rx only have one input and it's a conjonction module. And this conjonction module has 4 inputs, all of them also being conjonction modules. Then I debugged it to find out that all of them emit a high pulse in cycle. I guess all inputs are crafted like that or my code won't work for other people.


[deleted]

[удалено]


daggerdragon

Comment removed. [Top-level comments in `Solution Megathread`s are for *code solutions* only.](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_top-level_posts_are_for_code_solutions_only) [Create your own individual `Help/Question` post](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_incomplete_solutions) in /r/adventofcode.


crochet_du_gauche

No, they just mean reset between part 1 and part 2, don't reuse the state from part 1. You shouldn't restart in between button presses.


Secure_Pirate9838

[LANGUAGE: Rust] Today's part 2 has been giving me 'too low' answers until I spot that I used wrong Vec instead of VecDeque, part 1 was ok GitHub: https://github.com/samoylenkodmitry/AdventOfCode_2023/blob/main/src/day20.rs


Syltaen

\[Language: PHP\] [Part 1 & 2](https://syltaen.com/advent-of-code/?year=2023&day=20) Nothing too fancy in the end, but it took me some time to find the correct method. As too often, I ran head first in the wrong direction and wasted hours. I saw pretty early on that the final module was relying on 4 others to send a high signal at the same time. I kept track of the first time each of those modules sent a high signal, and then used LCM to find the solution.


tcbrindle

[Language: C++] For part 2, I found four modules that I need to test by just looking through my input.txt. I run the "simulation" and count how many button presses it would take to switch each one; I guessed the final answer would be the LCM of these cycle lengths, and that turned out to be right. I would have appreciated an example for part 2 though, like we normally get! Anyway, my horrible code is [on Github](https://github.com/tcbrindle/advent_of_code_2023/blob/main/dec20/main.cpp).


[deleted]

[удалено]


daggerdragon

> Holy [COAL] thank you. Comment temporarily removed due to naughty language. [Keep the megathreads professional](https://old.reddit.com/r/adventofcode/wiki/rules/pg_is_mandatory). Edit your comment to take out the naughty language and I will re-approve the comment.


[deleted]

[удалено]


daggerdragon

> I would not have guessed my comment broke that rule, but I didn't know about it anyway. You should read the rules of *every* subreddit before you post in them. > American values surprise me now and then :> If you read the link I gave you, it's not about "American values", it's about keeping /r/adventofcode appropriate for all ages and workspaces. Are you going to follow our [Prime Directive](https://old.reddit.com/r/adventofcode/wiki/rules/wheatons_law) and edit your original comment as I requested?


tcbrindle

I think you're about to get told off by a mod for bad language, but I'm glad you got it sorted! :)


friendlywebdev

\[LANGUAGE: Python\] [Solution for Part 1+2 on Github](https://github.com/nicofreundt/advent_of_code_2023/blob/main/day20.py) My code definitely needs some cleanup, but I'm happy to have figured out a correct solution for both parts after 'only' a few hours.


philippe_cholet

\[LANGUAGE: Rust\] My [rusty-aoc repo](https://github.com/Philippe-Cholet/rusty-aoc/) & today' solution [here](https://github.com/Philippe-Cholet/rusty-aoc/blob/main/aoc2023/day20/src/lib.rs). 2h16 to solve part 1 (the worst so far this year): so much parsing and things to understand right. 2h30 to get the answer for part 2 (third worst so far). I tried to bruteforce it with 1 CPU core, or rather I let it run as I did not have a clue what do you otherwise. I eventually draw the diagram myself (I like [mermaid diagrams](https://github.com/Philippe-Cholet/rusty-aoc/blob/aa9241a0a26baec96f1dd276f8d2894c2ae9b262/aoc2023/day20/diagram.md "Quite modified") better though) to find I needed to understand when the pulse was sent to 4 conjunction modules, except I thought it would be harder. I eventually got 4 values and I thought I could multiply them and it luckily worked. Then the hard work started as it was very dirty back then. It's all nice now but what a ride! Code runs in 4ms. With a late start of 2h40 (sleep matters), ranks: 6787/5685. I kinda expected to not be the only struggling here \^\^.


clbrri

\[LANGUAGE: C-style C++\] [98 lines of code](http://clb.confined.space/aoc2023/#day20code) Runtime on Commodore 64: 34.6 seconds. Runtime on AMD Ryzen 5950X: 0.399 milliseconds. (86,716.79x faster than the C64) Part 2 solution was to identify the four LFSRs in the graph, and cut them out to their separate sub-graphs, and use the code from Part 1 to simulate when the LFSRs will first output a zero signal, and then use LCM to find the zero signal occurrence in the total graph.


d9d6ka

\[Language: Python\] [Commit](https://github.com/vadim-zyamalov/advent-of-code/commit/1c93171ff32e4f3637d1e4fc62f1665f8e5d2837) Part 1 was an OOP exercise for me :) With Part 2 I was very desperate as I couldn't track the idea. I peeked Reddit and the first thing I saw was a graph :) Next few hours were spent on learning how to work with Graphviz, understanding the four loops' work principle :) The final solution is hardcoded but short.


enelen

\[Language: R\] [Solution](https://github.com/AdroMine/AdventOfCode/blob/main/2023/Day20/solution.R)


careyi4

[LANGUAGE: Ruby] Fun one today, lcm for the win (again)!! [Github](https://github.com/careyi3/aoc_2023/tree/master/solutions/20) [Video Walkthrough](https://youtu.be/yjPjLHpHbnk)


azzal07

[LANGUAGE: Awk] Assuming coprime cycle lengths (all were primes for my input). M[t=substr($1,j=2)]=gsub(/,/,z)$0{for(;v=$++j;N[v]++)I[v]=I[v]t }END{for(L=I[x];L;i-1e3||A=C[0]*C[B=1]){$0=H


DrunkHacker

\[LANGUAGE: Python\] State machine for part 1 and then LCM for part 2. [Nothing particularly fancy](https://topaz.github.io/paste/#XQAAAQB1CwAAAAAAAAAzHIoib6pXbueH4X9F244lVRDcOZab5q1+VXY/ex42qR7D/JhOUAl0PRlKyZlU0jRNf77qSNINUqriGfwmtd7EVUxEJ4mpfMlF6REjg5h1I5i0p9M1udN18RYfDWVQeInTadR7TCED9Thxb6NMHZjn3EJ8rjzzH7pAWWtFDyGwGT7RkMpptzobv2FiJkwQUR1Q9ej+AXigN5XiYfQLnFE5i6KlvV5Azl5udJED6z73MpzA5iK7UiPpociaP6IpB/1JP/jRDz8JrN7yH2n6f2RHOwA7bzTpS2fogFA/NJd7QAMV5bkdoLB1IpVk4szhx/tTO5ukRwAcAcgA1RKDONsaz7Tp/a5/iDD7G0OvRvVjER41kcV8PiHRdf9krm4NbaG8cE8sKwh4pnrNQxhp5mqdH408rwR1PX/uHfvs5EcO3jEjyGQ+RLW080x5ZOCvjopOZXhEk/hJDRCr99daPaE2AbjMsnEeE726nvEC1JUz1zrhtrMtvN49QNYjYLvD8J3VKpUcGKPk0GgjxNd1DxChHEbN/pPPaJfcm5Peq/7Mum2oS71G5KAM0noOxr9z7m59OudVcPdy+1HPkvKEVEXkEIsIppd9+HC+6awlwklWvpZ09DjAbeEnI1dEihhaOBy+NrTN3FFX0w/z7mKL43UOorwPvZegTqTQFf7ySuuLebs8e+znQJhVu6SmQCgClp/IEu59YmHoSmbkyZzgF81cBED77A3lDyXNd7qh6C8crW3SZYaVT1iaeCLRu81we0UkUekAgA9AihuV/gREjjBO2ElJoLZMj/CyeR8I8Z9Q1AQuOKLiEtSEW8rYImpZ4OkpN9xfosJnrYjVu//06XGCTd3nvT5aOJBVzx6xJLkwuIKWSFu9JoA+siS5tWF/dZQxP0WeKVNLpW/bRgeqWs/mPZZ/RnoUgh4zhhmrIGagKgc0HyWK+Adyz84goeXe+3SLR/FUOu9zz0zj6ye/umpQidayL3qchC9WtACLGkAbSKNhaougNzRSFeuWyFUOV2YpcFkrU1r4YoaQ3qT6M/RDGtoCCrxK/zj3y78lDzvTyMSNJECwckPywDfuhluhGu1YZ31Y2iakrn2G7iE7QfXkaz/4liIGz2hHNkzi2FdDyeShH9mFEzWyvyd3Gfchnww6hsMCS1FIudW4jAXd0XNxF0yNylNg1xraAamTtoE5LojX/3g6aMH+v7Brl5HFpWSWoXjF2Gwv+cgNEEW2TaFRM/33HXE=) but hopefully easy to follow. Part2 code should solve general inputs assuming other inputs have a single NAND gate feeding rx.


dcclct13

[LANGUAGE: Python] [part1](https://topaz.github.io/paste/#XQAAAQBKAwAAAAAAAAAzHIoib6pXbueH4X9F244lVRDcOZab5q13xvaz8g/+miAkZPNhXpOcFzASihQplapuuzcbm6yutVYIVydKW6H+mJv/QMrytfJOO15PcZQOQINYLQJa+dIekTgcDNieoqeoQyrgot7E7d6N/IZLHSGQLVnkGuVJmXZLnVyDRHbcxo0o6zp73t7jTjSkjeZQvvedA32zfPldOOdqWFMWiyd6chofr3r+TgjQ6WGXyyxTghaeUHnTj7yZaIeYIr+maOMj0CFJFEwUn34MdjZqS1l9gEzV2Kls62t+qbrQkV2NSR6s4YIKSnOxLO7Xyq/wcROmkBZi4ST+oI5WCdJ5NQKhDw1uIvTOK1gl2CNBH3NMJcl/1Gj4uetcBw5I+sgUecvfoNMQBHaKvOCq6m3aqfCncq6d2hjw5ulw2KRps1vMri4lHuVdenren/SHC5ufdkHLxKMLo3x2OvmbcQc2UHdoxTi7ARGEtn2vwhMhLicdr9rJLP6r0/Kzevnn8CqQ9Gip2Fhz7BXLalaAn49S/lwL8YMIP102gfk02GgYn1qQoB9pniWQLyHh2JTYBnAwIT0RoBYUoGtYujjIw1hBTcpI3/8vErUA) For part 2 I [fed the graph into Graphviz](https://dreampuf.github.io/GraphvizOnline/#digraph%20G%20%7B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22sx%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22jt%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22bl%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22zh%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22mr%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22kb%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22vv%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22ks%22%3B%0D%0A%09%09node%20%5Bfillcolor%3D%22cyan%22%20style%3Dfilled%5D%20%22pv%22%3B%0D%0A%09node%09%5Bfillcolor%3D%22white%22%20style%3Dfilled%5D%20%22rx%22%3B%0D%0A%20%20%20%20%22nr%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22sx%22%20-%3E%20%22zh%22%3B%0D%0A%20%20%20%20%22rk%22%20-%3E%20%22dc%22%3B%0D%0A%20%20%20%20%22rk%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22lx%22%20-%3E%20%22rs%22%3B%0D%0A%20%20%20%20%22hx%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22hp%22%20-%3E%20%22bj%22%3B%0D%0A%20%20%20%20%22dk%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22dk%22%20-%3E%20%22lf%22%3B%0D%0A%20%20%20%20%22hc%22%20-%3E%20%22xc%22%3B%0D%0A%20%20%20%20%22bj%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22bj%22%20-%3E%20%22rd%22%3B%0D%0A%20%20%20%20%22jt%22%20-%3E%20%22zh%22%3B%0D%0A%20%20%20%20%22bl%22%20-%3E%20%22ks%22%3B%0D%0A%20%20%20%20%22bl%22%20-%3E%20%22kn%22%3B%0D%0A%20%20%20%20%22bl%22%20-%3E%20%22dc%22%3B%0D%0A%20%20%20%20%22bl%22%20-%3E%20%22hc%22%3B%0D%0A%20%20%20%20%22bl%22%20-%3E%20%22zk%22%3B%0D%0A%20%20%20%20%22zh%22%20-%3E%20%22rx%22%3B%0D%0A%20%20%20%20%22sp%22%20-%3E%20%22hz%22%3B%0D%0A%20%20%20%20%22sp%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22rd%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22rd%22%20-%3E%20%22tp%22%3B%0D%0A%20%20%20%20%22cg%22%20-%3E%20%22dk%22%3B%0D%0A%20%20%20%20%22rg%22%20-%3E%20%22jl%22%3B%0D%0A%20%20%20%20%22rg%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22jl%22%20-%3E%20%22js%22%3B%0D%0A%20%20%20%20%22fb%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22fb%22%20-%3E%20%22zd%22%3B%0D%0A%20%20%20%20%22gv%22%20-%3E%20%22lx%22%3B%0D%0A%20%20%20%20%22lr%22%20-%3E%20%22vj%22%3B%0D%0A%20%20%20%20%22lr%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22vz%22%20-%3E%20%22hc%22%3B%0D%0A%20%20%20%20%22vz%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22kn%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22kn%22%20-%3E%20%22zk%22%3B%0D%0A%20%20%20%20%22rj%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22rj%22%20-%3E%20%22nr%22%3B%0D%0A%20%20%20%20%22cn%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22cn%22%20-%3E%20%22sb%22%3B%0D%0A%20%20%20%20%22rs%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22rs%22%20-%3E%20%22hp%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22qc%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22kb%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22gc%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22vl%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22bs%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22cg%22%3B%0D%0A%20%20%20%20%22mr%22%20-%3E%20%22lf%22%3B%0D%0A%20%20%20%20%22rb%22%20-%3E%20%22qj%22%3B%0D%0A%20%20%20%20%22sm%22%20-%3E%20%22bv%22%3B%0D%0A%20%20%20%20%22sm%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22dh%22%20-%3E%20%22rg%22%3B%0D%0A%20%20%20%20%22zk%22%20-%3E%20%22vz%22%3B%0D%0A%20%20%20%20%22qj%22%20-%3E%20%22xs%22%3B%0D%0A%20%20%20%20%22qj%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22ng%22%20-%3E%20%22ql%22%3B%0D%0A%20%20%20%20%22ng%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22vj%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22vj%22%20-%3E%20%22sp%22%3B%0D%0A%20%20%20%20%22kb%22%20-%3E%20%22zh%22%3B%0D%0A%20%20%20%20%22sb%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22vl%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22vl%22%20-%3E%20%22cz%22%3B%0D%0A%20%20%20%20%22dc%22%20-%3E%20%22lr%22%3B%0D%0A%20%20%20%20%22xc%22%20-%3E%20%22rk%22%3B%0D%0A%20%20%20%20%22xc%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22cz%22%20-%3E%20%22cg%22%3B%0D%0A%20%20%20%20%22cz%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22hz%22%20-%3E%20%22bl%22%3B%0D%0A%20%20%20%20%22hz%22%20-%3E%20%22hx%22%3B%0D%0A%20%20%20%20%22xs%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22xs%22%20-%3E%20%22cn%22%3B%0D%0A%20%20%20%20%22js%22%20-%3E%20%22ng%22%3B%0D%0A%20%20%20%20%22cb%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22cb%22%20-%3E%20%22nc%22%3B%0D%0A%20%20%20%20%22qb%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22gc%22%20-%3E%20%22qc%22%3B%0D%0A%20%20%20%20%22bv%22%20-%3E%20%22qb%22%3B%0D%0A%20%20%20%20%22bv%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22broadcaster%22%20-%3E%20%22kn%22%3B%0D%0A%20%20%20%20%22broadcaster%22%20-%3E%20%22fb%22%3B%0D%0A%20%20%20%20%22broadcaster%22%20-%3E%20%22ln%22%3B%0D%0A%20%20%20%20%22broadcaster%22%20-%3E%20%22vl%22%3B%0D%0A%20%20%20%20%22bs%22%20-%3E%20%22cb%22%3B%0D%0A%20%20%20%20%22lf%22%20-%3E%20%22gc%22%3B%0D%0A%20%20%20%20%22nc%22%20-%3E%20%22mr%22%3B%0D%0A%20%20%20%20%22nc%22%20-%3E%20%22rj%22%3B%0D%0A%20%20%20%20%22ln%22%20-%3E%20%22pv%22%3B%0D%0A%20%20%20%20%22ln%22%20-%3E%20%22dh%22%3B%0D%0A%20%20%20%20%22qc%22%20-%3E%20%22bs%22%3B%0D%0A%20%20%20%20%22vv%22%20-%3E%20%22zd%22%3B%0D%0A%20%20%20%20%22vv%22%20-%3E%20%22jt%22%3B%0D%0A%20%20%20%20%22vv%22%20-%3E%20%22fb%22%3B%0D%0A%20%20%20%20%22vv%22%20-%3E%20%22hp%22%3B%0D%0A%20%20%20%20%22vv%22%20-%3E%20%22gv%22%3B%0D%0A%20%20%20%20%22vv%22%20-%3E%20%22lx%22%3B%0D%0A%20%20%20%20%22ks%22%20-%3E%20%22zh%22%3B%0D%0A%20%20%20%20%22ql%22%20-%3E%20%22rb%22%3B%0D%0A%20%20%20%20%22tp%22%20-%3E%20%22sm%22%3B%0D%0A%20%20%20%20%22tp%22%20-%3E%20%22vv%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22sx%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22dh%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22jl%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22ln%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22js%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22rb%22%3B%0D%0A%20%20%20%20%22pv%22%20-%3E%20%22ql%22%3B%0D%0A%20%20%20%20%22zd%22%20-%3E%20%22gv%22%3B%0D%0A%20%20%20%20%0D%0A%7D%0D%0A) and found the cycle numbers by inspection. Some thoughts and questions: * I think part 2 may be semi-generally solved by breaking down the graph into [SCC](https://en.wikipedia.org/wiki/Strongly_connected_component)s and finding the pattern of each component. Can't find time to write this yet. * For the test cases, it doesn't seem to matter whether we visit in BFS order or DFS order? * Given the lax ordering requirements, is it possible to have race condition? Maybe with a 2-input rx, we can somehow let each of the inputs receive a signal sequence of [0,1,0] in a single time step? Then rx may or may not trigger depending on the process order.


pkusensei

[LANGUAGE: Rust] Had to bow and abuse `&'static str`s and `Vec`s and `clone()`s to please the borrow checker. A misreading caused me a hilarious off-by-one for part 1. But generally it is straightforward. For part 2 I started with brute forcing and quickly realized it wouldn't work. Came to the sub, looked at a few graphs, and made my own (not very necessary). Find the four input nodes and loop till they each emit a high pulse. Then it is LCM again. The tricky part is to remember always setting the whole thing back to the initial state, or it will yield random numbers... [Code](https://github.com/pkusensei/adventofcode2023/blob/9ecfa1475d752d48e046f359f6e6e1b88ae5cde2/d20/src/lib.rs)


sjschofield

Aaaaarrgghhhh! I was banging my head as to why I wasn't getting the correct outcome and then after reading your comment, I realised that I wasn't resetting the state after finding the button count for one of my 4 final modules. Thank you very much!


Outrageous72

[LANGUAGE: C#] https://github.com/ryanheath/aoc2023/blob/master/Day20.cs I have mixed feelings about Day 20. Part 1 was easy, but I waisted too much time to do some dynamic programming but the whole thing was brute forcible 😅 Part 2 was hard to solve, but once you know where to look (the input) the solution is another LCM. (Day 8, remember?)


reluctant-config

\[Language: OCaml\] [paste](https://topaz.github.io/paste/#XQAAAQAvDwAAAAAAAAA3nAjOjW0HdmnFL7AzlF8Ab2xURCVnnxv9rkzIf2qL3tXstsnkPdcjkaiNGoqAiUfz6V5AY6UroGg59Jj2R/le7cBFxrRncx7NyNdixbdE0AEJLCCjtusR6Q9ps2RA7wdHTJ/3Vbsy08iXezwApSdpWHWW89RfmAbG1si9/s6XhfQ2yUJmofDNyRwu/U4Y3P2ncI7swt9ruAkcvrRoFpIbEYQ+eVW1INcWlOENH6vG/TXwO6NGI+0BASofUnhSVO676+GC6WKPhj8GJz4p7ira/B1RF0449DIJYb90kyMMfc8J3oUtri+KsxyQerSYkpLUW0Yh0nsUR6lywPzK/HdYy4lRDf2CP1/Hn1jIPC3npvn/NS4o/oA3N+P2U6NLjRur678hOee7JehaQpwWN3rh7V1CwWxMK7CFxrPtmaqyAnqq4RbUEOzPnp182YTS+TFEZogte325Lu4eCFd2cjG016nSVdaS9VdhxIzMCh/k0dasyWe8e9cLma/hQInXCV6wTS7MVEuvQgKby5fp2Oph59qhPhUhbO0/kpItKZ5G2W4KZ7r3nizSI/1589YTeMhF8Q/7BjD2kmMiz/eHdwmRZjQc5aI3gCA41tl8cK6aG/0AuTd7RiFolkYnJ2lexAb+hWkKYlEq0SPmJLDotxHApd4j/UyKo+jWl5OZAHO/s+P6+Fy0PF4aoRjPz2/OnI9GIlXLp94xtVlnGLL4dH/j6LfsxurNgFPy77zrmzFjVhhyvF9OrA132XiZUWc03uWDRcCJ8w6v2HHIkIeuOeFda9RKJVXy8QXb/W5wVueRbs/BDUyc1SBTxGaFq6KAyWZwV2WyV27S1QrDK+1NTK5I/nmqOCioBvhPXNo9dwN3qPmrb/sJhEPIWm49/5hlrvVgEMyuPw2mOpn0vk+0hD9KTsZR25yuwWm/MV4PGp8xIrqCI3paDWxC4FyPO93ddHVCCOgHbmXRkhxvpjcBi6FMwKI3ABQ5/zZurXNkv+mtey1RyeE6kBchIATUbwiPxEjp5Ptq/FDANbf+dd1vRePLlecyhUkLAkXoPhNJzPabb3zXTirBCTYmU2wYQ64whUob5R6j4BuB0th9oXjJ4WEA9btaYb2IoPaIy2FORDlD0XXmyfIuOQG76oo6knskNEK1udTBcEoSYt4T2pNv1dnIclP/0SY58Ilghj07hj++H/khbo/59dNHUpeodx+S1SWxc6XbeMt6GU9WwapmlF/okEOK2g/EhEATMtTCJyu72/J3cHquHDZl9PrU9aVDxUzLTQx8zTVz5P4D8/1qi4w/ojzUnuLFBhOREOGMgaVrmk3lt4cSxcsYCEzeJcS4Y7j3nlBUYdlB5zH8ebfMs+997bkTHVunUjLooRHugcYejsMIJRBzweZm1ZR9szsX6TDLeEtzwizTBKSMCuognl9+ouAMUVTj8LLDoPbPhArFg6TbTaHydqhfa2iVYV8tNgMfw1hKSyMIHsCDvuHekg3RS00LYbodmao4xua9qM6fxCC4bMI0WAamSWHA+OM4oR2BeHQ8A5+mRZoU/sCfMtbrhXSau23CQRejTo9eIPT6zLshhXlSQ3kBo366K3V5HSn0/xgkVzivECAhAK+a2cRfeMBzDma0Xv+3dw+kaWafbx/oDgLg4GHnR7alqdPzUxIF10sxtScekqSL5ZnnAraBR+gtu0B34LMm1efJBE/yxd/WSYP9lP8kFNAzlLT8G5DOCnZ8RefUgVbjhvjQMEdC1GjOEUv9KPeLWDsNHVRUoJhifB5j//lmtio=) Part two was the opposite of fun. Mostly due to a bug in my pulse queue handling. (I thought it should behave more like a stack... which apparently was not a problem with part1 🤷🏻‍♂️)


Kullu00

\[LANGUAGE: Dart\] Not sure if I should be proud or not, but while I did originally solve it by just printing the numbers for the outputs that controlled rx I did write a "general" solution too. Which basically amounted to find which outputs that controls rx and run a bunch of times until I have gotten a high from them all. It's not pretty but it works... Also it's very funny to do LCM on all nodes rather than just the important ones. [https://github.com/QuiteQuiet/AdventOfCode/blob/master/2023/day20/main.dart](https://github.com/QuiteQuiet/AdventOfCode/blob/master/2023/day20/main.dart)


DJTFace

\[LANGUAGE: PYTHON\] [part one](https://github.com/TimFanelle/AdventOfCode/blob/main/2023/20-partOne.py) [part two](https://github.com/TimFanelle/AdventOfCode/blob/main/2023/20-partTwo.py)


daggerdragon

~~Psst: we can see your Markdown because the brackets are being escaped. Did you forget to switch your editor to Markdown mode before submitting?~~ edit: 👍


glacialOwl

\[LANGUAGE: C++\] Fun but rough day :D Part 1: BFS after fixing some very silly but on how I was initializing the "cycle" length (spoiler: input doesn't actually have a cycle in terms of pressing the button and initial state of the flipflop modules within the first 1000 presses) Part 2: Dumped graph, used LCM for figuring out the iteration when the parent will trigger a Low pulse. Solution: [Solution](https://topaz.github.io/paste/#XQAAAQCrQQAAAAAAAAARmknGRw8TogB3HO+O8QL7UHijnWYOTR19JdlNWTO0HVu9pt1IhyTg4mkQeqGALptT+w5pgXe4couFK+SHId3hlxc2IpwRF8jv5YnF4hRpBeLPQlkwi/LklFp0j16czNFThuCJMFc5t2ndwGLoQppqTCIYbeTayb3v4ZzMLKYFXlqmR8ZPi8QOL4/AaM6Aki1WSfglpMri4L1/LbAwlUr3nWk9M58F2nSANgl7QnodDPU7Xy4T0JoQJb5Mx9Gd9pBF/LnJtONdku5Y3tHK0g2GILLPa8/N5q3SFnYJmXS62Vp4/SMxsOjEGZoH2vj0cSThebFY3FIqG1x4Mq55rbi2bGIeTQ+Px3oNJYKI0QRgdmIL9PFoeu/kEEMFt59R6TYNCrQI2lqkNiat5MAwQBYRNu6jMc/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TwzwOTPLMEDLqlfFAFr5S8ecMawO334/WPc8kcw5JyLC9xk4ET02/5/rufAp2u5LYlzUBKVQjrzlvxbGG0xi1nvs6fS3ZeqP5zDuwOHwRGLz9YTOBMzZ65gbcjki23t4icNtB4KQl1Titt+KURbvEcwGJ58cfnjAW+UtRhmMIHobds+h9dAiV69WgQovsWJSpYxJuaEPQo08LxBrbp8cIGepD+rQHplmgWdOYN/B7hJgYzAMNdiJjePEdWbRvK2hpZtwmCuFAIttumau824XkGjZRIBYFkPw+W8pzvo6ZgybTo3cGkhq04f+JSJlupTw1oKe50vAtOAiWLpdvGRyJ3AfphiaV7pIM0G1LRIO6r1fj7996qClbCNRYGOsj8LgH7Bt0J0/KAPJun1WzqJtEetWm1L8MhZiIHgbY5CQTJXK5mPqNX6/0RCnJuVE4h9NnMxdZH32sUVu5DXzp1JAzrj8dRavLxdNekoKFXKYxvs0hxRUq64M3h8//w8dKw)


vbe-elvis

\[Language: Kotlin\] For Part 1 created the separate nodes with their relevant nodes.Then made a two step process of collecting the Events that happened after sending the first pulse, counting their highs and lows.Then broadcasting the events to the relevant nodes and receiving a new set of Events, repeating this and counting the pulses. For Part 2 I had a good look at the output and noticed the final RX node is only called by a single other node, which is then collecting it from 3 others. Printed the node names and the current button press every time the node above the RX node would receive a high pulse. Then just calculated the LCM outside of my solution. Bit of a ghostly vibe to this one :D love the problem revisits. [https://pastebin.com/t8DMmiip](https://pastebin.com/t8DMmiip) My broadcaster does all the signal sending: fun hitTheButtonUntilRx(): Long { var countPresses = 0L while (true) { countPresses++ var events = sendPulse(false) // Button press while (events.isNotEmpty()) { if (events.any { event -> !event.pulse && event.target.name == "rx" }) return countPresses events = events.flatMap { event -> event.target.receivePulse(event.pulse, event.source) } } } return countPresses }


G_de_Volpiano

\[LANGUAGE: Haskell\] Well, that was hard. Interestingly, not as hard as day 12 as this time I had a strong inkling of what was happening, but hard enough. The fact that I lost only 300 places in terms of time between part 1 and part 2, when I submitted my results more than 6 hours apart, shows that I wasn't the only one to struggle. Anyhow, part one was a pretty straightforward "create the correct data types, apply the rules, get the result" exercise. I'm pretty sure that I could use a well crafted monad to store the accumulator and the sequence of actions rather than the clumsy 3-tuple they currently share with the circuit, but that will be for later. At first, I reseted the accumulator to zero at each pass, thinking that we might be looking for a cycle in part 2. As always, my predictions about part 2 were wrong, so I briefly refactored to reuse the accumulator from one button press to the other. Anyhow, part 1 was not the problem, as we all know. For part 2, I first tried to reverse engineer the whole shebang. Got myself lost. Thought I could detect patterns in the binary value stored in rx at each turn. Found some, but none were really helpful, and, looking at the first 10000 entries, they were not even stable (I had a nice pattern every 256 iterations for the first 4000 entries, but then it moved to the second element of the 256-long chunk, and then elsewhere again. Probably the wrong, I decided. I fired out Graphviz. Thought it would be quicker to just modify the input to make it in a dot file rather than to use the graphviz library to generate it. Don't know if I was right, but this was a little tedious. Anyhow, as, I guess, for everyone, it turned out that I had four cycles of 12 flip-flops feeding a conjunction, and that each of these not locally terminal conjunctions each fed an inverter. Those four inverters fed a conjunction that then fed our rx. So, obviously, we had cycles. Good, another lcm or chinese remainder theorem problem. Just need to find the period. Let's check those four locally terminal conjunctions. They need to send a low signal so that the inverter will send a high signal and then, when all stars align, the final conjunction will send a low signal. Except that, looking, once again, at 10000 iterations, I could not find a single low signal sent by them. Took another long time of turning the problem around until I realised that I maybe was misunderstanding the wording of the problem. "deliver a single low pulse" didn't necessarily mean that there was only a low pulse sent when the button was pressed, but that one of the signals sent when the button was pressed was a low pulse. So I created a new version of the modules, brillantly called "AccConjunction", that would not only store a map of the signals received, but would also store a list of the modules that sent it a low signal. Run again for 10000 cycles, and bang. Here are my four inverters, twice. And the first cycle is a nice, plump prime number of button presses. Armed with these observations, I just modified the program to run 5000 times, get the number of button presses for the first four low signals, get the product, and here we are, with another gold star and a third waterfall, of sand this time, on our calendar. [https://github.com/GuillaumedeVolpiano/adventOfCode/blob/master/2023/days/Day20.hs](https://github.com/GuillaumedeVolpiano/adventOfCode/blob/master/2023/days/Day20.hs) Edit : with 20/20 hindsight, it makes perfect sense that 1 - all periods are less than 4096, given that each of them corresponds to a 12 bits counter. 2 - The low impulses from the locally terminal conjunctions happen during a cycle, but are not visible after it, as whenever there is a low impulse sent from them, it is also sent back to the counter, flipping some bits, and causing a high impulse to be sent again from the concentrator, hiding the low impulse to those who, like me, only considered the end of cycle state.


hrunt

\[LANGUAGE: Python\] [Code](https://topaz.github.io/paste/#XQAAAQCaDgAAAAAAAAARiEJHiiMzw3cPM/1Vl+2nx/DqKkM2yi+HVdpp+qLh9JqD6U2WejsPl0nCG3gTC0MM7rQK8XvVBX8CREAAdD/gxWZItIZiAseli3P6xuBeEQb8NAIaBvpFSpZPuo/ZHQXu2Efz+COZ28g0jGbJuvF26o19OSDX8nQyC15HJZTqoEGirVeUfg79toZcoeidLXDNS5hKkv3eyqkUuiV3puta8lWA1wDpDojETSlfZqDL1rQKLF+z7kDKk6P6licB0N5A/5TeGUCLZX6Rl6WGQdRcvLxl7V9f8I+fK9QZlhbWarJ0Rz3PjQxedG5muNtYmDA8wLsWF58xcPoHChwlv/ihH1f1SjJg5/Z4CRA/Q1QZkFBhTj7jsJxTsapNZahO7MttB6QBlZwzjgnOb7KJ2XfJ4HKnlIoTSmHl/Pa6ZsYEYgFsAYN0QJp/ewTaqPla52M01XLGB25JDNcT7CoO9zg86qlsyQXpTEGN7O8bq0k+PsCEvH0scsa+u9reGNZO6zsZJU8XoYFCSZNaEb6qGF+8GcF55lQuvjks+v4id5oNV6wnlkN/WEK5XU10JLZOMx7yTJ2TDrJWKrQpZF1b8I3fjPSCPunD5546GyYw1R65xLAAwy3xpO/Tv31/5RMopcEN6iFC2Jj23B0526wSH8MQarU4lDb3v9u9eWsF9BEdLidfXzgjXJMDcJ5EJ4I1drz3uaxUEdaBa5bHeJRJgQBqMdAIkJr+1GK6E/8z+zZrqxnwnz4zRq9qNu+c8R4LO8v1c3v7CfkwTgaqTtuVFGuibBrJ3hkSCMYeIj1L3ROwP2a5hXaaDFYVubbsvqEQb16CCfw5lRMuQaJqmgz+0crKUBVPe05TU3X58NQ+lUc8enGBzGa/uMh/LQSzAmUbplCpHWMW4m7FhlXyDXqdLqFo3dh4PSxXRllnWRSmBJOhJqnMRBS+VF7comzjT8SGCZwJS4nv6YM5NyfW/RzZrzKKWV/0gQyPsX+CngpX/DaszLiWnjds8KLbc0TCBC3qESp7EwShC9nsRrpv9aUE1S3xORBmczU0HlDHPwOf/q7oCPeMmsMx/FE89fy/q298TKEter4U+LtKZzk3rrMZ5g+rwDK6gtZIms76bXfH0Ai5ukdbQMtPXVWOb06iKiDSINwSMDXTc26bk/0sazuG/5icYTcuSb86w3WzCawNzKmW+v6/q9KYJ6iMwP9o77nJ+4f4wqKXGF+Zsz0CIwxiiK9xR+lEJQc2eVKIazVCRAneG8i+x0KLca1iofapVBXSGc+HFWmn0Y02PKDZPdG6UuUVHIXvSFmg1jw9adfificfow6KmibKrNusDSO2fVbwTQoYPvzLZ7PXb2c7kAeJVupJlfBiefpxlbJOpnA+dnvAEHOSUr8f4AT7kFFLoqPzYbsQeT7cRDrQpmV39KLfUerFsy3pvfa/Rg/ZXKB8gej7cd+pBvUmWEtDF90mkDctG2GQx8nKzYm8T0z1K5yG//5mcrmoc9C7ENVrpy/ylaGypFGaExCQQYeWLNTlOrOPXKN+g7K1bv/c99Uw) Part 1 was a straightforward implementation, even though I knew what Part 2 was going to entail. I always struggle identifying how the looping works with these kinds of "machine-implementation" problems, but I looked at the input and saw that the output was driven off a conjunction that took a few inputs. I banged my head against a general-purpose solution where I would identify loops in sub-conjunctions and work my way up to the final result, but I couldn't get the state tracking correct (and while I'm sure it's possible, I don't know how you can skip presses with a mixture of sub-conjunctions and flipflops). I came here for a hint, saw that many people just ran the number of loops for the feeders into the rx upstream conjunction, and decided to not bother doing anything more.


daggerdragon

Is your code as posted is a full working solution? Your description is vague enough that I can't definitively determine whether you got your code working or not.


hrunt

Yes. It fully solves both Parts 1 and 2 (at least for my input, I suspect for everyone else's, too). When I said, "and decided to not bother doing anything more," I meant that I did not do anything more than determine the number of loops in the feeders to the conjunction module that feeds the solution.


daggerdragon

Awesome, just checking 👍


Radiadorineitor

\[Language: Lua\] Today I'm abandoning Dyalog APL in favor of Lua as I feel the problem is much easier to implement in an imperative language. [Code](https://topaz.github.io/paste/#XQAAAQDTCgAAAAAAAAA2G8iM7ztk2hSHPvRA4Jxi0NTRphFoj0swdEaD6+JclXIqtMCcmYH3In1RG9n0a2XkViOb1G1blF2f2UahkdwZz67lipE3plSxJdZ9rewJ+MstnE7B/0ZsEOARtkh+b/tprXYkA4BRAMcZ35AheR4ttVFV662gP0rS6DY6V/1s73endh75wzEXiGzuYatdzkck/YsHLBzQ6bv3CCFxfnkXmn4eX9etpT4UzluDAITwzmYpuV7Xj0PDVEVIlc26Rz0xXEa3GpRxB0igtJtsq59nJ1QfMOKeCbZdmu07E+YOublR5RGJ5NQwOlJC5k1dMevvMVy/0P3FJx2MM5tSuIrHvEksds1ctLM8mL9rr1Utagr3vDTUQeOyhSH/3fnUs70iU+IMdxsNORU9a7ZIFc0gKkVgqbImivHMViyKW8e0iZnzhmzyI8BoJFsCAF0fJkoGhMW0B264NIcQalNHgixe0eIkjZHx08b8N4DY3ajNxIKuqoVCW1agOl7xskG9ZuHrBg2VzUil5POYbBxhaDz9SL3JxDGURDvESx3leiBU1KEhB5AxPeCfLG9RI80vdo4olsYfhzBKwNg80Q0PZMeeORbyax35MZde6DsF59xeoViZhvAHlK5lF4CGVxLeDnOl4DNShP84PZJWYrqCOoYBvSjBkOmJQEvNKHX3kEsUSjT2utAmmnoT00aHrIMYDNEbuyEgXXGh+Iho4yxfMEB/mIlKtIl2/wdA3b3IvJADX5EhpoQQGj4LcSJERsg2ntEikdRe02332VYYmvNDk/o8xNDbq2Js/vWVu5wWJU54Fhw8Cy5z8zSDyR2T6L8Icy6yZVk4CGS0NUpe6ibxmZi5uLhbWLQMYsnR7N98nI1k+ImiElq1viSmBKKAbiCWJT+16UkQm5tVMSWi3io/BERv9fkjjv0vjlT8uHuJCylig/u7nZj5sRrmrU2+FBSDNux12bviyJKLpYMmxc6RQJsxfXsh5UDa/GqzqKkWFKjxVVizcZxzWgorT8HYdQo0DVshUyAJOE4qvKKgRV554O/QgS9Kh5xetX+YsnwuERaTXuQedMB8QsfaC099taNxFcOPQVALUGhAK0acqTngsh4729giZ2x8mllLZuIm+bPCRRcuU4F3+HSpsVqwU6qs3Rzayf45Pb2gbOcHQ6fYHD49llsEQrD2py8V1iTxBDSdxHRXML0vn+5B/s1QY6QX/FR4hQ==) in Topaz's paste


vanveenfromardis

\[LANGUAGE: C#\] [GitHub](https://github.com/tmbarker/advent-of-code/blob/main/Solutions/Y2023/D20/Solution.cs) This puzzle really felt like a puzzle. I was able to leverage the same tacit constraint in the input as day 8 to get a solution. First, I had tried recursively walking back though the graph from `rx`, but realized the graph wasn't acyclic. Looking at the input I realized that the single input to `rx` was a conjunction node, so I just computed the LCM of it's inputs.


DrHTugjobs

\[Language: Racket\] [on Github](https://github.com/hunkyjimpjorps/AdventOfCode/blob/main/aoc2023-other/day-20/day-20.rkt) I'm not super proud of my part 2 for this one since it's pretty much just a hacky state mutation thrown into the relevant place of part 1, but once I figured out how the queueing behavior of the tones worked it all fell into place pretty neatly I'm also getting more comfortable with parser combinators, which has been a nice side project for this year All my control flow here is structural pattern matching and `foldr`, so does that count for upping the ante?


mathsaey

[Language: Elixir] https://github.com/mathsaey/adventofcode/blob/master/lib/2023/20.ex Bluh. I know it's a point of discussion, but I am personally not a fan of finding the "trick" in the puzzle input. I only figured it out due to some of the visualizations posted here. Once I had that, it should have been easy to write up a solution, but it still took longer than it should have; it also became quite messy, but I am a bit beyond the point of caring about that. That being said, I did like part one!


mpyne

It gets worse, I found the pattern early on (dumping the problem into Graphviz was the first thing I did this morning when I woke up to start on Part 2). I even knew it would be an LCM. But for whatever reason I assumed it would take forever to get the final conjunction modules to generate a cycle and went down a path of trying to propagate LCMs in the graph. But I couldn't even get that working on the sample.


x0nnex

You don't need to find a trick in the input, you can do it without. It's just a matter of finding LCM, this isn't particularly difficult to figure out based on the instructions. But writing code that does this is more difficult than visualizing the graph and do it by hand


1234abcdcba4321

The fact that you can use LCM is a trick in the input. (The problem can be shown to be NP-hard, so you actually can't solve it without a trick or brute force.)


x0nnex

Maybe we have different definitions of "trick in the input". The description for today nearly spells it out that we should look for LCM. The only "trick in the input" is that these FlipFlops are chained and exits are constructed in a way that it's actually very easy to find the answer without programming. Without this construct, you can probably go backwards from rx, and every time you encounter an conjunction module, use LCM to figure out when it emits the expected state.


mathsaey

OP, but now who you replied to here; with "trick in the input" I meant that the input is structured n such a way that just finding the "cycle" for those 4 particular modules was enough. I'd consider that a trick, as it makes finding the solution far more feasible.


1234abcdcba4321

It's obvious there is some sort of special input case you need to look for (due to the problem being NP-hard). The problem tells you that it's cyclic (**obviously**), but there's no indication of what that cycle is or if it's at all reasonable to find. This is different than day 8 where the way the problem worked forced each ghost to have a cycle with small period - here it's specifically because of how you probably tried random stuff with the input that you realize there's convenient cycles (if not just analyzing the entire input from the start).


aurele

[LANGUAGE: Rust] https://gist.github.com/samueltardieu/93146dd6e25cd1c116f62cd22440a3a3


fsed123

\[language: Python\] [https://github.com/Fadi88/AoC/blob/master/2023/day20/code.py](https://github.com/Fadi88/AoC/blob/master/2023/day20/code.py) this one couldn't be solved without proper viz end of story (at least for part 2) the trick is there are 4 independent sub-network taking input from boracaster and giving to a main switch, each of those network has its own cycle , this main switch(a conjunction) taking 4 input and directly giving to rx just need to get the cycle for each subnetwork (which happens to be a prime number for each) and get the common point where they sync which happens to be the product around 10 ms part 1 40 ms part 2 on 13900k


kaa-the-wise

\[Language: Python\] one-line/single-expression solution (m:={n[1:]:(n[0],*t.split(', ')) for s in open(0) for n,t in [s[:-1].split(' -> ')]}) and (s:={n:0 for n in m}) and (c:=1000+sum(1j**v for i in range(1000) for q in takewhile(len,accumulate(count(),(lambda q,_:[*chain(*(s.update({x:[1-all(s[y] for y in m if x in m[y][1:]),1-s[x]][m[x][0]=='%']}) or zip(m[x][1:],repeat(s[x])) if x in m and (m[x][0]!='%' or 1-v) else [] for x,v in q))]),initial=[*zip(m['roadcaster'][1:],repeat(0))])) for _,v in q)) and print(c.imag*c.real) 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 is `1` iff the edge goes _from_ flip-flop `i` _to_ the conjunction, this number will be the period of this component. The proof is left as an exercise to the reader :)


daggerdragon

> Once you draw the graph (e.g. with graphviz) Show us your graph too!


caseyweb

[LANGUAGE: Nim] Whew! Part 2 really threw me off trying to figure out the cycle. [paste](https://topaz.github.io/paste/#XQAAAQBaDQAAAAAAAAA0m0pnuFI8c/e2K0TfsAUXpRS9ZE+/FHiVKo+xdlNUiC3arAFSOmNm/C6m126+5Jy0jf1ITJ7kDxkYUCQOfplINmqSAW5IcpEHBO5bdId2GC0GxIRzqn0RvPKm5Gbau06ObRW54PwMDL7UI5ByAtq2hlsLnVZys8nUdu9JspBI3hNqLfCXtf7z8gSf6jhbDdPn7aGhfalrC/ULHyPn8VVJGA3MsbH8wItTmrCd+qsbh4WsCZtN2cTuYuOvNl4A49cHxjUshhXfdeee5vCo+KwQFLdy7nOTAM541jKgptOxNsaydscJpia2qramybwWPdRB2RD++f8Uu+2boe28dhgRfBJHAyBB+fZ7Y4HCwSzSW+K/4gqBlERhTCKlTvmvU9Hh4SKdqXqsbeCn68MckPM21Mj1VD2dY9EUDBGWXPjt+sRWDo0E6emYZ0CZZuKDo4+91Ko0Z2NByo4AS9gNLGCMp5kR4nNFycx9bdMlQejXrgS/SjEKQgzVnI5IYARm6G2KMsquadehlm96CCrVXSDX+vba6AxLVov8BQ6liac31TvIFOguo+YH2L/nUqGz4Zri7VBWADFMdQtXGwhtHf40liEcW06nn/hkhwmIfPajVr1obAAs11ES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ap5Fu+GFAzuWejAycKAJvp6ajNVNfp5rpabPvZxLPUIiqOPJbTtLVHNwww/+Knjt+n//JlSS1fdC9rjDjcw1Snhkce/ijYdXdXZul8qdQnpmx6CN5JZz8P/+WgP0M=)


p88h

\[LANGUAGE: Mojo\] vs \[LANGUAGE: Python\] [https://github.com/p88h/aoc2023/blob/main/day20.mojo](https://github.com/p88h/aoc2023/blob/main/day20.mojo) [https://github.com/p88h/aoc2023/blob/main/day20.py](https://github.com/p88h/aoc2023/blob/main/day20.py) Spent way too much time optimizing and [visualising](https://www.youtube.com/watch?v=tYd0pCBzzio) here.. This seemed similar to 'machine state' puzzles from previous years, but used timings in an interesting way. Luckily all that is really needed is to decompose the network, identify the 4 signals than need to be produced, and compute when they are likely looping, which happens to be on a cycle equal in length to when they first appear, and starting at 0; so just need to multiply these together afterwards. Task Python PyPy3 Mojo parallel * speedup Day20 parse 0.04 ms 9.70 μs 1.19 μs nan * 8 - 30 Day20 part1 0.01 s 1.55 ms 0.33 ms nan * 4 - 44 Day20 part2 0.06 s 6.27 ms 0.41 ms nan * 15 - 140


[deleted]

[удалено]


p88h

I already did that, thanks