Our great sponsors
-
How about a python translation of my haskell solution?
-
F#, Converted TypeScript solution to F#, List.choose made it more easy. Under 80 lines part 2 only code with Type specific modules.
-
Scout APM
Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.
-
Seems plenty fast though! And I get nice trees of cubes and their subcubes that are lit. https://github.com/hermanstehouwer/adventofcode2021/blob/main/lib/cube.ex if you are interested.
-
My subtraction algorithm always generates 6 cuboids, except when there is no intersection. It then discards the ones with size 0.
-
Rust, 286/106. I just compressed the volume by every distinct coordinate, then summed up all the dx * dy * dz subvolumes. Only required 500MB of RAM! Could've been 8x less with bitvec.
-
advent-of-code-2021
My solutions for Advent of Code 2021: https://adventofcode.com/2021 (by BradonZhang)
Python (140/111)
-
SonarQube
Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.
-
Rust
-
Pluto.jl notebook (requires your AoC session to fetch your input)
-
-
My thoughts exactly. I did the cube sub-division thing. In order to not get lost, I directly wrote "clean", tested classes for 1D range and cubes. Overall it was a smooth ride, got me my personal best (1232nd), but at the cost of >20s execution time! Now I feel humbled by the solutions I'm seeing here.
-
Free Pascal - 2251/1744 34.5 seconds runtime No objects, no recursion After brute forcing part 1, I stared at part 2 until I though only handling the different values of X,Y,Z and letting the grid represent variable size cubes.. only to hit memory size limits anyway... and then I learned how to use BITPACKED array, and was able to eventually brute force part 2. Whew!
-
Raku 5216/1574.
-
Elixir, Python 1708/791
-
Python
-
C# 3039/1750
-
JS 727/2619, but was interrupted for ~3 hours doing part 2.
-
-
Code available on GitHub.
-
Rust
-
My solution in Go. The first part is ugly but wanted to do it faster.
-
I came up with a similiar solution, but i forgot to include the possibility for multiple turn offs and ons, so your solution helped me out form my own. However, I somehow still get the wrong answer, if anyone could help me I'd really appreciate it :D https://github.com/ckainz11/AdventOfCode2021/blob/main/src/main/kotlin/day22/Day22.kt
-
-
-
-
My code is not yet as efficient as it could be: i takes about 4-5 seconds for both parts.
-
-
Rust
-
-
Should've seen that coming in part two
-
Golang
-
I used the same basic idea in my non-recursive solution. However mine is MUCH slower, probably because it requires a lot of list manipulation that isn't necessary in the recursive approach.
-
In the rest of the code I simply iterate through cubes and multiply the edges with the saved values.
-
rust
-
-
PHP
-
-
Well, I ain't proud of today but it is what it is. Egel code for day 22, task 2, and a with pretty colors.
-
Python takes around 1 minute for both parts, no extra libraries.
-
Here’s pretty much the same thing translated to TypeScript: https://github.com/N8Brooks/deno_aoc/blob/main/year_2021/day_22.ts
-
Haskell (Part 1 only)
-
Ha! I had the same idea. I feel smart now :) Rust
-
Python: set arithmetic... with cubes
-
My Solution
-
warning, code is crazy ugly
-
Your first idea wasn't that bad, if you just figured out a smarter way to generate less cuboids, like in this solution or in mine.
-
Witness the weirdness for yourself at this here link: https://github.com/codemicro/adventOfCode/tree/master/challenges/2021/22-reactorReboot (includes screenshots)
-
Rust GitHub. My approach is to go through all cuboids and always remove their intersection with all previously added cuboids. Then, If it is a "on" cuboid it is added to the list of cuboids. This way no cuboids will overlap and I can sum all their volumes in the end.
-
-
full code
-
-
Kotlin, Python, and Rust solutions are the same solution but much uglier.
-
Rust https://github.com/Crazytieguy/advent-2021/blob/master/src/bin/day22/main.rs Imagining the geometry of this was very tricky for me. For a while I contemplated if calculating the intersection of each pair of cuboids would give me enough information to know how many cubes are on at the end, and finally decided that I would also have to calculate the intersections of those and so on, so I gave up. Instead I decided that my state will be a vector of cuboids that are garuanteed to be non overlapping, and on each command I would subtract the current cuboid from each of these non overlapping cuboids (leaving 1 to 6 cuboids depending on intersection), and finally either add in the current cuboid (for on command) or leave it out (for off).
-
-
Anyone got any ideas why it may fail? Here's my solution. Input data is here and I've triple checked that it's pasted correctly.
-
Zig
-
-
I think my part 2 is one of the simplest solution I have seen so far and still runs decently fast (200 ms on my MB Pro) - even though there are many much faster on here.
-
-
Python
-
code here on github
-
-
Rust
-
thank you! this is the most easy and straightforward approach to this problem. the only downside is the speed — it's not great. my golang solution takes almost 2 seconds to compute final answer.
-
-
-
-
holy shit, your solution is amazing. It's so clear. It took me a day and a really complicated solution to get the answer in more than 5 mins runtime (https://github.com/Harshsa28/Advent_of_code_2021/blob/main/src/22.py).
-