Our great sponsors
-
It's convoluted and there are way cleaner solutions based on recursion and memoization; the only merit is probably that it's a bit more efficient (in Raku, at least, compared to the re-implementation of this Python solution).
-
F#, Under 60 lines, readable code, takes about 200ms (for both the parts) , Learned about flag #nowarn "40" to achieve true memorization.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
Python, 198/34. Part 1, part 2 is below as it's mostly self-contained.
-
-
perl5 62/702
-
adventofcode
Advent of Code solutions of 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 and 2023 in Scala (by sim642)
My Scala solution.
-
Yay memoization!
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
GitHub
-
Mine, Python 3.10.
-
Raku 3364/1406. Memoization cached 22828 trees, saving 135153328222302 wins for part 2, so it ran in less than half a minute, which is a big improvement over the last two days.
-
Javascript with a non-dp approach and no memoization. Recursions go brr!
-
-
Code On Github
-
F# solution in Jupyter Notebook. Got some help from this thread.
-
Full Source
-
Rust
-
I'm doing the same cached recursion in Kotlin, Python, and Rust.
-
-
Python. Part a is whatever, part 2 is pretty clean. I wonder if there's a math-only solution to this?
-
Thanks! In the meantime, I was able to slash the runtime in half by using a faster hash (fxhash) for the cache.
-
Today was my cheatday as I used the tidyverse library :) github
-
C++ 5173/3650
-
-
Python solution. https://github.com/kupuguy/aoc2021/blob/main/src/day21.py
-
Pascal 2235/4609
-
source
-
advent-of-code-2021
Discontinued Code I used for solving https://adventofcode.com/2021 (by pavel1269)
-
For p1 used streams to imitate infinite dice rolls. For p2 had to refactor to be able to cache effectively using Memoize. Finishes in ~500ms.
-
Full code is here: Github
-
Java
-
Extrapolation code
-
Elixir, 167 ms on Part 2.
-
Wow. Almost identical to my solution! https://gitlab.com/RedPixel/aoc2021/-/blob/main/day21/day21b.py
-
Python, part 2 runs in ~0.3 seconds.
-
Part1 was quite easy, so i created a Dice and Player object, which are able to roll und move.
-
C++
-
-
task 2, and with colors, with impure memoization. spend most time figuring out generators
-
Rust: https://github.com/nj-vs-vh/advent-of-code-2021/blob/main/src/day21.rs At first I misread the second part and forgot that dice are thrown more than opce... Banged my head against the wall trying to figure out some clever way to iterate through possible move combinations. Also got sidetracked trying to solve the whole thing modulo 10. When I finally understood triple dice throw, it became feasible to brute-force the puzzle for distinct move values while keeping track of the number of universes this happens in. It's not too elegant but works in 2.5 seconds.
-
full code with part 1 I used a State monad for part 1 just as a refresher.
-
Scala. Doesn't have the convenience of functools.cache like Python, but you can get the same behavior using a mutable.Map and using .getOrElseUpdate!
-
-
-
-
-
-
-
-
This is my fast and final approach btw https://github.com/kolonialno/adventofcode/blob/main/matsemann/Day21.kt
-
-
-
Thanks goes to andreaferretti's memo library, too!
-
-
-
Clojure (GitHub). I see some elegance in my part 1 solution, but sadly it was entirely inadequate for part 2 :(
-
Not sure if you are open to any tips about slightly improving speed, but our part twos are really similar.
-
-
Completed part 2, see GitHub. I couldn't really use the same `DiracDice` class and simply use another `Die`, but had to create a separate `DiracDice2` class.Basically, just keep track of the possible universe state and their counts, and try all possible combinations of die rolls. Keep playing until all universes have a winner.
-
-
-
-
-
Misunderstood part 2 at first but I knew it would be a dynamic programming thing simply based on the task itself. This let me eventually clear up my misunderstanding. Had an ugly solution where I always switch between player 1 and 2 based on a toggle, and then saw this beauty so I that clever switching as well.
-
-
Straight forward (=not optimized) solution that takes ~10 seconds to run. https://github.com/christianfalck/adventchallenge/blob/main/AdventOfCode/Day21.cs
-
Part1 was so simple that it's not worth talking much about it. My solution to Part2 is:
-
C++ 17 solution, part 1 & part 2 run at 129ms [Github](https://github.com/giorgosioak/aoc-21/tree/main/21)
-
My Rust solution: https://github.com/CastleQuirm/AdventOfCode/blob/main/year21/src/day21.rs
-
-
advent-of-code-go
All 8 years of adventofcode.com solutions in Go/Golang; 2015 2016 2017 2018 2019 2020 2021 2022
-
github: Part 1 This felt rather easy, so I tried to write things in a nice way, hoping it wouldn't be too challenging to extend. I'm reasonable happy with how the code looks, but the extensibility was definitely missing.
-
Part 2, on the other hand, was more much complicated. I noticed beforehand that it was unfeasible to simulate every last of the trillions of possibilities, that it was necessary to keep track of the win counters in some other form. But I could not figure out initially how to do it. I looked this thread for ideas, and managed to understand the strategy. Credits go to u/SwampThingTom for the idea ([this comment](SwampThingTom), and the code behind it). After understanding the approach, I implemented it on my code (instead of copy/pasting).
-
Kotlin
-
-
Chez Scheme (Part 2)
-
Clojure (GitHub). 3 seconds. Well, I tell myself I'd rather write readable code than super-concise code, anyway.
-
-
-
-
R
-
My solutution in Python. Using itertools.cycle for part 1 and functools.cache for part 2.
-
advent-of-code-2021
My solutions for the https://adventofcode.com puzzles (2021) 🎄🎅 (by ClouddJR)
Kotlin
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives