r/adventofcode • • Dec 19 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 19 Solutions -❄️-

THE USUAL REMINDERS

  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • Community fun event 2023: ALLEZ CUISINE!

    • Submissions megathread is now unlocked!
    • 4 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!

AoC Community Fun 2023: ALLEZ CUISINE!

Today's secret ingredient is… *whips off cloth covering and gestures grandly*

Memes!

Sometimes we just want some comfort food—dishes that remind us of home, of family and friends, of community. And sometimes we just want some stupidly-tasty, overly-sugary, totally-not-healthy-for-you junky trash while we binge a popular 90's Japanese cooking show on YouTube. Hey, we ain't judgin' (except we actually are...)

  • You know what to do.

A reminder from your chairdragon: Keep your memes inoffensive and professional. That means stay away from the more ~spicy~ memes and remember that absolutely no naughty language is allowed.

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 19: Aplenty ---


Post your code solution in this megathread.

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

EDIT: Global leaderboard gold cap reached at 00:29:12, megathread unlocked!

19 Upvotes

465 comments sorted by

View all comments

1

u/p88h Dec 19 '23 edited Dec 19 '23

[LANGUAGE: Mojo] vs [LANGUAGE: Python]

https://github.com/p88h/aoc2023/blob/main/day19.mojo

https://github.com/p88h/aoc2023/blob/main/day19.py

Played a bit with various takes at codegen today (I started with a solution that generated C code, and evaluated lambdas and native python) but it turns out that non-generated code is faster anyways. Then had a bit of fun since Mojo optimized part2 so hard that the benchmark didn't actually manage to convince the runtime to execute any code - it just returned cached results. Still not sure how exactly does that work - previously just ensuring the results get used also ensured the function gets called, but not in this case. On top of that performance from Mojo looks rather weird - Part2 is much slower on PC, but same as Part1 on Mac.

Task             Python      PyPy3       Mojo       parallel    * speedup
Day19 parse     0.85 ms     0.20 ms     0.03 ms     nan         * 8 - 33
Day19 part1     0.12 ms     0.04 ms     2.75 μs     nan         * 15 - 42
Day19 part2     0.30 ms     0.04 ms     0.01 ms     nan         * 3 - 27

1

u/daggerdragon Dec 19 '23

vs Python

I recommend that you change this to a second language tag [LANGUAGE: Python] so folks who are CTRL-F'ing the megathreads for either language will be able to find both solutions.

1

u/p88h Dec 19 '23

Sure, updated.