-
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.
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
adventofcode
Advent of Code solutions of 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 and 2023 in Scala (by sim642)
-
advent-of-code-2021
My solutions for the https://adventofcode.com puzzles (2021) ๐๐ (by ClouddJR)
-
Advent-of-Code-2021
Made it through all 25 days of Advent of Code for the second time! (by Leftfish)
-
advent-of-code-2021
Discontinued Code I used for solving https://adventofcode.com/2021 (by pavel1269)
-
aoc-2021
Discontinued Advent of Code 2021 [Moved to: https://github.com/TenViki/advent-of-code] (by TenViki)
-
aoc-2021
Advent of code 2021 challenges written in Rust to learn the language and get more comfortable with the it (and sometimes I just use C++) (by tglane)
-
adventofcode
My collection of Advent of Code solutions in a slightly overkill project setup ๐๐ป (by marcelblijleven)
-
advent-of-code-2021
My Advent of Code solutions. I prioritize readability over performance where possible. (by tcc-sejohnson)
-
AdventOfCode2021
Some solutions for as much of advent of code 2021 as I can be bothered to do. (by TomHemery)
-
advent-of-code-2021
Discontinued Trying to solve https://adventofcode.com/ [Moved to: https://github.com/ThePituLegend/advent-of-code] (by ThePituLegend)
-
AdventOfCode2021
Advent of Code 2021 challenge: 13 different languages, one chosen at random every day! (by Qualia91)
-
advent-of-code-go
All 8 years of adventofcode.com solutions in Go/Golang; 2015 2016 2017 2018 2019 2020 2021 2022
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
C code. I'm afraid I went a little overboard with double checking everything. Are there even pairs for which no rule exists? If there are, I'm good :) Runs very fast in 180 ยตs on a Pi 4 @ 1.8 GHz:
I wrote this bottom-up DP solution, and it's not a dead end :)
TypeScript, no string manipulation, kept two maps, count of pairs from last step, and count of polymers, took just a counter change for part 2.
Python, 8/28. Part 1, Part 2. My part 2 turned the input into "a Counter of adjacent pairs of characters", which you need to be careful about because turning that to "a Counter of characters" is not easy - you double-count all characters except for the first and last which cost me an incorrect submission!
Python 73/287
My Scala solution.
Solutions in C++: Part 1 Part 2
Rust. Ended up doing it recursively, like last time. 4ms on part 2; pretty sure that's because I keep cloning hashmaps.
Go 1449/3191
Go (search: golang)
Part 1 & 2 Optimized
Perl I expected second part to make a surprise and do something different than just increase number of loops - but It didn't :)
Python:
Some F# since it's pretty underrepresented: https://github.com/nicklecompte/AOC2021/blob/main/AOC2021/Day14.fsx
Common Lisp. Pretty bad day, stumbled around for like an hour trying to actually construct the strings for part B and then finished in like 10 mins once I realized how to take the better approach :/
Kotlin
It's a simple iteration in yours, I like it. I complicated things by recursing and maintaining letter counts the entire time.
In the end it turned out pretty nice
All solutions
Kotlin, Python, and Rust are all following the same pattern.
Rust solution
python
Cleaned up code: [email protected]
C#
F# https://github.com/bainewedlock/aoc-2021-fsharp/blob/master/aoc-2021-14/Solution.fs
For first part implemented the task logic actually calculating the polymer each iteration. This was slow enough for part 2 so had to scratch my head for a while.
I'm not sure what kind of brainfog descended on me this morning. After part 1 I instantly knew I should just count the pairs and update their numbers but somehow couldn't figure out how to do it. It took me almost an hour before it dawned on me that...wait for it...a pair splits into two pairs. After that and some off-by-one debugging I came up with this solution. Defaultdict for the win.
Elixir
Python
GitHub link - keeping track of pair counts and character occurences.
I had the same approach. A bit different details in the end (double counting yadda yadda). Here is my code!
Optimized Rust Solution
Part 1 of course generating all the strings Part 2 reworked :D Visualization here: https://www.reddit.com/r/adventofcode/comments/rg5h8e/2021_day_14_visualization_with_a_chart/ Source code for both parts: https://github.com/TenViki/aoc-2021/tree/main/14
My solution in javascript
C++\ Part 1 was brute forced at the beginning. Both parts were rewritten to get part 2.\ I think the lesson is to think DP-wise right away as soon as you notice the structure gets bigger real quick
My solution here : in typeScript (a bit too verbose... but hey, it's working :D)
Python 3.10 (source with docstrings)
My C++ Solution
Python day 14 solution (GitHub). Tried splitting out the logic into individual functions to aid readability.
using my templates.
< 30 lines of python
Scala. Would have been a lot easier in Python with a proper Counter class. This isn't super idiomatic (i.e., functional) Scala, but it gets the job done
cleaned up my code a little. Both parts run in 40ms. Full code with comments is on github
GitHub/Polymerizator.java
Rust First time working with Rust on this years challange so its probably not idiomatic but im trying to get more comfortable with it. Feedback is welcome
GitHub [Source w/ comments] [Execution profile for 40 steps]
Rust: Solution
Python 3.10 solutions, standard library only
C# solution, I keep letter pair counts in a square grid and a separate map for individual letter counts
repo
Tricky memoization / dp problem today
My solution in Go
y2021/day_14.ex
C#. 15ms avg for part 2. Insight is to maintain a single letter frequency count AND a letter pair frequency count.
C# source P2 Runs in about 800 us avg. Using a tokenized dictionary after I ran out of memory once building strings. The lanternfish strikes back
Egel, the element count is just either the sum of all (_,B) counts plus 1 for the head of the template, or the sum of all (A,_) counts plus 1 for last of the template. Just project on either the first or the second element.
Python day 14 where part 2 is a bit messy but it seems to be very efficient.
This was a bit difficult. My original part one solution worked completely differently to what I had to do for part two.
Github Link
Node.js solution
Package with everything
C# code on github
C solution.
Compare my part 1 answer to see what I mean.
See solution: https://github.com/tcc-sejohnson/advent-of-code-2021/tree/main/14
This is literal witchcraft to me! How on earth did you get this to run instantly for 40 steps when mine essentially just uses a linkedlist instead of a dictionary and takes hundreds, if not thousands of hours and TBs of RAM to run? https://github.com/jcreek/advent-of-code/blob/master/2021/14/Program.cs
C# Github Part two took me some head scratching, got to one off the right answer but ended up needing a pointer from the sub for the trick of initializing the element count and counting additions only. Also I had spoilers before this that part two would be ridiculous after all the lantern fish memes, but I felt I should do the brute force approach for part 1 anyway.
I was stuck on the counting part (after being stuck in the How should I solve the massive string being massive? part hahaha). So I finally came here for some hints, and found your code. And this comment saved the day: # The only new character we've added to the overall string is the new # added element. The quantity is the same as the pair that generated it # For example, 25 ABs will generate 25 new Cs if the rule is AB -> C Actually I'm kinda scary because our codes are fairly similar :p There's some simplifications/contractions/tricks maybe you'll benefit from (even though my code is far from perfect in its tricks): https://github.com/ThePituLegend/advent-of-code-2021/tree/main/day14
Ruby solution optimized (~8ms to print both parts) by precomputing 41,000 values
Python
Rust in ~600us
Github source, with documentation. I solved this using a level-order traversal of the graph of inserted polymers.
Rust
Below is the new solution, which works for part 1 and 2. The full code is on GitHub.
Clojure, source and tests. Brute forced part 1 but refined the solution for part 2 which runs in about 30ms (not bad, I'd say!).
Part 1 (Rust) - pretty simple.
A bit late, but I got there in the end. Using the same "counting pairs" trick as everyone else. Writeup on my blog and code on Gitlab.
Python, with imports of any library. Part 1, inefficient and slow. Part 2 using try/except statements and pair counting, quite fast I find it.
My Solution in Python. This one is pretty compact and amazingly fast thanks to collections.Counter and functools.lru_cache. Here is the function for counting the elements:
Golang Part 1 using brute force Part 2 using memoization