Our great sponsors
- Revelo Payroll - Free Global Payroll designed for tech teams
- Sonar - Write Clean Python Code. Always.
- Onboard AI - Learn any GitHub repo in 59 seconds
- InfluxDB - Collect and Analyze Billions of Data Points in Real Time
-
My solution was to pretend it's a Stream and treat is one using a small abstraction: https://github.com/premun/advent-of-code/blob/main/src/16/BitReader.cs
-
Looks somewhat similar in approach to mine, but instead of keeping track of the number of bits consumed myself, I simply re-use the position that it already keeps track of, plus a tiny bit of user-specified state so that I can parse directly from the hexadecimal representation, no need to build an intermediate String for the binary representation.
-
Revelo Payroll
Free Global Payroll designed for tech teams. Building a great tech team takes more than a paycheck. Zero payroll costs, get AI-driven insights to retain best talent, and delight them with amazing local benefits. 100% free and compliant.
-
Parsing is made by implementing an Iterator giving next bits on every iteration. It may be interesting to write nom parser for this format - I've chosen to write everything by hand. I think it turned out pretty well, my solution runs in 6ms for both parts.
-
Here's my Day 16 if you're interested: https://github.com/bozdoz/advent-of-code-2021/tree/main/16
-
Python 3 143/89
-
-
-
Sonar
Write Clean Python Code. Always.. Sonar helps you commit clean code every time. With over 225 unique rules to find Python bugs, code smells & vulnerabilities, Sonar finds the issues while you focus on the work.
-
-
Solution
-
TypeScript: https://github.com/ElCholoGamer/advent-of-code/blob/main/src/days/2021/16.ts
-
-
-
-
-
C# 2283/1968
-
Go, 2758/2421
-
Rust
-
Raku, 2388 / 2366, which suggests that everyone else who worked at my pace also quickly realized that part 2 would be "Evaluate the stack of values."
-
C# (2247,3170) Recognize from part 1 that this is gonna be a pseudo programming language. Spent most of part 1 implementing lexer and parser. For part 2, i implement a Visitor pattern for fun but got bogged down with "number too low" in debugging while the logic is already correct.
-
Perl Original solution was full of substr(), in last commit it's much more tidy... I left few die() asserts here and there in case I wanted to mess with the code again ;)
-
Python 3 (3546/3543), object-oriented solution
-
-
-
Rust iterator approach
-
source
-
Python 3 1903/1496 (GitHub)
-
C# https://github.com/LEPT0N/toybox/commit/f18b2e492a697d65bfb274e441fbb2dde439abc6 Probably took me longer to parse the instructions! Got to use BitArray, which is fun since I've never had a reason to do that before.
-
Common Lisp. Christ this was a sad day. I probably had part 1 in 40 minutes (or I would have if emacs didn't start hanging which necessitated a huge apt-get update/apt-get upgrade 40 minutes in), but then I got hung up until ~3hrs by the "padding" stuff and trying to parse more than one root-level packet from the string. Uggghhh.
-
Today was rough. Code is too long to post here. Github Basically using indexes and a bit of recursion for this.
-
Java, the code is still a mess, but if you need some tips, it might help.
-
Python
-
PHP
-
-
On github
-
-
Using Python3
-
-
-
Pascal 7079/6330 - github
-
Parsing
-
-
I enjoyed this one, despite all the reading. Felt like a nice change of gear from yesterday's. Using recursion to read sub-packets from the binary string, using a function that returns the value (or version sum in part 1) as well as the length, so I know where to read from for the next sub-packet.
-
-
GitHub
-
-
-
GitHub link - I didn't know how to call my parse_packet function if I got a specific length vs a number of packets in the operator, so if I get a specific length I call the function recursively and if I get a number of packets I call it N times without recursion.
-
-
-
-
-
Rust
-
Python 3.10: source
-
Loved today's puzzle after I didn't really enjoy yesterday's at all. Solved it in Python and finally installed Python 3.10 for it - gotta say that Python is slowly becoming okay for language implementation stuff :D https://github.com/SV-97/AdventOfCode2021/blob/main/Day_16_2/main.py
-
AoC is definitly getting harder. After giving up on yesterday's (for now) I'm kinda glad I managed today's. Javascript solution
-
-
-
Classic recursive descent https://github.com/schoelle/adventofcode2021/blob/main/16-go/decode.go
-
-
both parts
-
Rust
-
Haskell. Reading the input in a monadic way with State, the rest is quite straightforward.
-
part1.rb
-
Well save to say, this was my least favorite puzzle since 2018: and I still had a lot of fun :) I used two global variables: one keeping track of the current index and adding up the version numbers. I am praying that there won't be a follow up on this :D github
-
main.rs and lib.rs.
-
main.cr
-
AdventOfCode2021
Some solutions for as much of advent of code 2021 as I can be bothered to do. (by TomHemery)
C# Github
-
-
Link
-
Here is my Rust solution.
-
Github
-
Rust (GitHub)
-
Python Github
-
Ugh, what a mess.
-
-
-
JavaScript 21/19 [Code] [Video]
-
J solution https://github.com/Toanuvo/Advent-of-code-2021/blob/main/J/day16.ijs
-
For part 1, the version (and other things) are attached to the metadata of each sexp, and a Specter recursive path is used to extract all of the versions.
-
-
Ruby
-
-
Once I finally understood how the examples worked with subpackets, I was able to come up with what I think is a nice clean solution. I ended up using an Iterator that got passed around to various sealed types that would parse themselves out. I defined several extension functions on Iterator to make things easier to read.
-
-
-
-
-
-
-
C#
-
Here is my Python day 16 solution
-
Rust
-
-
-
Clojure
-
[Rust](https://github.com/cdparks/advent2021/blob/cdd3d94e8da7be5cbc04b5d2bf73e23c6a0b9a1b/advent/src/day16.rs)
-
I used an iterator for going through the binary number. I wrote the results in a 1d array which gets cleaned up and finally converted to a string and executed with eval(). https://github.com/HrRodan/adventofcode2021/blob/master/day16/day16.py
-
-
-
-
first AoC this year that forced me to write a lot of unit tests, so I at least build the solution in a block-by-block basis, instead of writing the whole thing as a single piece of code https://github.com/SuddenGunter/adventofcode/tree/main/2021/day16
-
adventofcode
AoC solutions and visualizations for the years 2021 (Julia) and 2022 (Kotlin) (by LiquidFun)
Kind-of code golfed and hacky solution. Prints both part 1 and 2. Repo.
-
R solution
-
PHP Recursive Function
-
-
Javascript
-
-
Github
-
-
F# with Jupyter Notebook. Learned how to use recursive types today! Half-way through the problem I was starting to wonder whether BITS was going to be the new IntCode.
-
-
-
Common Lisp
-
adventofcode
My collection of Advent of Code solutions in a slightly overkill project setup ๐๐ป (by marcelblijleven)
-
Okay, I am posting it here for the sake of completion, but I don't think it is any good, and I didn't like the problem much. Rust: https://github.com/ropewalker/advent_of_code_2021/blob/master/src/day16.rs
-
Part 2 0.022ms (22ฮผs)
-
PyJpegDecoder
A JPEG decoder made in Python, that supports both baseline (sequential) and progressive images.
Not too long ago I made a JPEG Decoder in Python, which used a similar logic than the current puzzle, but on steroids. This gave the the skill set to tackle the puzzle in a relatively efficient manner.
-
-
F# Late to the party, easy puzzle today helped me to finish F# implementation for day 16. Used List.unfold probably for first time, referred a lots of F# solutions posted here, learning a lot, Thanks again.
-
C
-
https://github.com/fbl100/advent-of-code-2021/blob/master/day_16.py My first attempt at this was really ugly. The second attempt used a buffer that keeps track of the current position, which was much cleaner and resulted in everything just 'falling into place'. I say that until I got the part 2 answer wrong. I had to figure out why a negative number was getting into the mix on my evaluations. Check line 221-223 if you're interested.
-
My solution in Python. This one was fun! Thanks for the many samples and the detailed description.
-
Solution
-
AdventOfCode2021
Advent of Code 2021 challenge: 13 different languages, one chosen at random every day! (by Qualia91)
-
Python day 16. In part 1 I apparently do the parsing from hex to binary wrong, however, it works. This gave me problems in part 2 so I reworked that (and the rest of the code).
-
advent-of-code-go
All 8 years of adventofcode.com solutions in Go/Golang; 2015 2016 2017 2018 2019 2020 2021 2022
-
Onboard AI
Learn any GitHub repo in 59 seconds. Onboard AI learns any GitHub repo in minutes and lets you chat with it to locate functionality, understand different parts, and generate new code. Use it for free at www.getonboard.dev.
Related posts
- [2022] [Angular / Typescript] Collection of all visualizations I created this year as an interactive website
- [2022 Day 4] [Angular / Typescript] Interactive website to visualize your inputs
- Demystifying bitwise operations, a gentle C tutorial
- -๐- 2022 Day 15 Solutions -๐-
- How to organize Rust code for Advent of Code puzzles?