Our great sponsors
-
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.
-
AdventOfCode
My Advent of Code solutions. I also upload videos of my solves: https://www.youtube.com/channel/UCuWLIm0l4sDpEe28t41WITA
-
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.
-
aoc_ts
Discontinued 🎄 Advent of code solutions written in TypeScript for Deno. [Moved to: https://github.com/N8Brooks/deno_aoc]
-
adventofcode
Advent of Code solutions of 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 and 2023 in Scala (by sim642)
-
Advent-of-Code-2021
Made it through all 25 days of Advent of Code for the second time! (by Leftfish)
-
advent2020
Advent of Code 2020 solutions that optimise effort, tastefulness and brevity in roughly that order (by combatopera)
-
AdventOfCode2021
A collection for my Advent of Code (www.adventofcode.com) solutions using Nim, Julia, and Python programming languages (by genius487)
-
advent-of-code-go
All 8 years of adventofcode.com solutions in Go/Golang; 2015 2016 2017 2018 2019 2020 2021 2022
-
advent-of-code-2021
Discontinued Trying to solve https://adventofcode.com/ [Moved to: https://github.com/ThePituLegend/advent-of-code] (by ThePituLegend)
-
advent-of-code
🎄 This is my set of awesome solutions for the Advent of Code puzzles (by garciparedes)
-
advent-of-code-2021
Discontinued Code I used for solving https://adventofcode.com/2021 (by pavel1269)
-
advent-of-code
Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels. (by letelete)
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
That's one of the utility libraries I have in my repo, found here. I open my IDLE editor at the root so I can just import lib.aoc without issue. Not only can it download the input from the server but it also knows how to submit an answer (I have the program ask me if I want to submit *before* submitting just in case the answer smells completely wrong though, don't want to get hit by a time penalty for obviously wrong answers!)
Rust, 61 lines
I didn't find an easier way, your solution looks almost identical to mine in structure, only I matched enums describing direction.
Kotlin solution, fairly concise with minimal maths involved.
My solution in Rust. I defined a few types (Grid, Line & Coordinate) and implemented a bunch of traits to try and make it "Rusty", but that may have just needlessly added to the line count. Anyway, Feedback is always appreciated. :)
My solution uses namedtuple.
Python. 154/251 :( Video of me solving.
Day 5 Solution Python: https://github.com/CoconutJJ/AdventOfCode-Solutions/blob/master/2021/day5/day5.py
Go, 2582/2520
Python!
It helps that you can add two Counter objects together :)
perl 939/1020, cleaned up - on the rush I forgot about <=> operator...
Python 3 with NumPy, plotting grids as inline PNG images in a notebook.
Python (1538/3726) Video of me solving here (may still be uploading): https://youtu.be/b56Q6mBP6Nw
Nothing too fancy, I overloaded the stream in operator to read the lines from the files. Sadly the DrawLine function turned kinda ugly once I handled diagonals. https://github.com/BreadFish64/AOC/blob/master/AOC/hydrothermal_venture.cpp
Java 17, if you are looking for one. (However, it is not really a Java community...) I was really lost in diagonals, and it is not an "elegant" or less then 100 bytes of code solution, but I hope it is readable, if you are lost...
In Go, leaving out the file reading functions (full code here)
C++: https://github.com/UnicycleBloke/aoc2021/blob/master/day05/day05.cpp
The full code with comments lives on Github. But here's the meat without comments for brevity:
Python 3.
C# nothing noteworthy other than LINQ saving the day again
python x, y = x1, y1 counter[(x,y)] += 1 while x != x2 or y != y2: if (x2 != x1) x = (x2 >= x1) ? x + 1: x - 1; if (y2 != y1) y = (y2 >= y1) ? y + 1: y - 1; counter[(x,y)] += 1; see https://github.com/nathanesau/advent_of_code_2021/blob/main/solutions/aoc2021_day05.js
python clean version
Python (gh) (pic of vents)
Here's my solution using F# and Jupyter Notebook. Here, I didn't even bother creating a grid. I just kept track of all the points.
Java
In Janet (janet-lang.org) : https://github.com/BenningtonComputing/advent-of-code/blob/master/2021/jim/5.janet
Common Lisp. There's a really easy refactor to unify both days, but ehh https://github.com/anlsh/advent-of-code/blob/master/2021/src/day-05.lisp
Raku, MIT license, line breaks removed for brevity:
My Scala solution.
my rust solution for day5:
Python. A bit verbose, but readable (I hope!).
Haskell 3133/1662
Ruby again; incredibly janky, wasted 2 hours on "optimizations" that did not actually optimize, and forgot tally existed, but it works.
Rust
Go, accidentally solved the second part first: GitHub
Non-programmer joining this year's aoc :P C++ on GitHub
My solution in Rust. Overall happy with it being clean, especially compared to Day 4 :D
F#: https://github.com/Fubuchi/advent-of-code/blob/master/2021/Day5/Day5.fs
Dyalog APL p←⍎¨¨'\d+'⎕S'&'¨⊃⎕NGET'p5.txt'1 to←{⍺+(×⍺-⍵)×⎕IO-⍳1+|⍺-⍵} f←{x1 y1 x2 y2←⍵ ⋄ ∨/x1 y1=x2 y2:(x1 to x2),¨y1 to y2 ⋄ ⍬} +/1<{≢⍵}⌸⊃,/f¨p ⍝ part 1 g←{x1 y1 x2 y2←⍵ ⋄ (x1 to x2),¨y1 to y2} +/1<{≢⍵}⌸⊃,/g¨p ⍝ part 2
Yet Another Rust Solution
Solution and Tests which helped me find a lot of bugs. My initial solution didn't work with right to left and bottom to top going vents.
Python and another reason why defaultdict is my best friend. Not clean enough yet - I can probably get rid of the repetitions...
Rust solution
very nice. I am also learning golang during this aoc, and it took way more lines for me. I ll keep an eye on your solutions! (mines are here: https://github.com/lnguyenh/aoc-2021 )
Created a specific iterator for the ranges, that made the code quite nice. rust fn solve_p1(input: &str) -> usize { let mut lines = HashMap::<(i32, i32), u32>::new(); for ((x1, y1), (x2, y2)) in parse(input) { if x1 == x2 || y1 == y2 { let steps = cmp::max((x2 - x1).abs(), (y2 - y1).abs()) + 1; let xs = Range::new(x1, x2, steps); let ys = Range::new(y1, y2, steps); for p in xs.zip(ys) { let point = lines.entry(p).or_insert(0); *point += 1; } } } lines.values().filter(|&c| *c >= 2).count() } Full code is here
As always parsing the input takes most of the space. I did not bother writing my own loops to fill the diagonals and I used Eigen instead - github
RUST
Python
My solutions: https://github.com/ilvez/advent-of-code/tree/main/2021/day_05
Source / Blog
GitHub
Part Two wasn't super efficient (takes like 5 seconds?) but I made a pretty simple solution in Python
I used numpy and regrex for almost all problems so far. GitLab
On github
Rust and its lovely iterators: https://github.com/samueltardieu/aoc2021/blob/main/src/day5.rs
solution 1 and solution 2
Source (Github)
I'm using my vector type again for the coordinates. For them I defined these two types:
Full code in GitHub.
My solution in Python. Now it starts to get interesting. I need to remind myself to use collections and itertools more often.
Bless Python's sets! Makes checking for membership such a breeze!
Part 1 GitHub explain.dalibo.com
Github
Day 5 Solution in Rust
OCaml solution for the first part:
Learning Julia through AoC, would appreciate any tips or pointers people have. My solution might be a bit terse, as I'm trying to limit line count, but there might be better ways of doing that.
github
gitHub
Scala using foldLeft over a Map[(Int, Int), Int] and then just counting
Overkill Go solution. I had used Bresenham algo when I saw first part, turns out it was not necessary in part two.
Python day 5 solutions using Bresenham's algorithm (Github)
C# / linq FTW: https://github.com/graemefoster/AdventOfCode/blob/main/src/AdventOfCode/Day5/Day5.linq
Go, complete solution. 355/239
X86 assembly (linux) (also on github: https://github.com/jonay2000/aoc2021/blob/master/day5/day5.S)
My solution in Python. Nothing to boast about: lazy brute force, if that makes any sense. The optional dependency on tqdm helped muster patience.
My solution in Python. Nothing to boast about: lazy brute force, if that makes any sense. The optional dependency on tqdm helped muster patience.
Rust
F#, struggled a bit with diagonals. https://github.com/wegry/AdventOfCode2021/blob/main/Day05.fs
my day5 pt 1 python code
I've been learning fp-ts (https://github.com/gcanti/fp-ts) recently, so I've mostly been implementing them with that, though with some time pressures I'm occasionally dropping in bits of imperative code here and there.
Day 5 - Hydrothermal Venture
second commentrust this time
Solution
Github, Twitter thread
Solution
Solution
JavaScript - both parts https://gitlab.com/adventofcode-2021/day5
Go https://github.com/sebnyberg/aoc/blob/main/2021/day5part2/p_test.go
Python
My rust solution: [Day 5 - Github](https://github.com/abhinavr93/AOC2021_Solutions/tree/main/Day5)
Rust: https://github.com/ropewalker/advent_of_code_2021/blob/master/src/day05.rs — I am sure it could be made faster and prettier, but, alas, I couldn't think of how.
Here's my pretty verbose solution in Python (probably will be easier to read on github than here): https://github.com/jszafran/advent-of-code-2021/blob/master/day-5/solution.py
Nim, Julia, Python
What an elegant solution. Mine takes over 350 lines.
The orientation calculation could be done by matrix indexes operations https://github.com/FlakM/aoc2021/blob/main/day5/task1/src/main.rs and then its easier to create ranges. You can also use some clever crates and get some calculations for free https://github.com/timvisee/advent-of-code-2021/blob/master/day05b/src/main.rs
The orientation calculation could be done by matrix indexes operations https://github.com/FlakM/aoc2021/blob/main/day5/task1/src/main.rs and then its easier to create ranges. You can also use some clever crates and get some calculations for free https://github.com/timvisee/advent-of-code-2021/blob/master/day05b/src/main.rs
I am wrangling the input with tidyr and then refusing to actually code the solution with tidyr as well, so here goes nothing: a truly incomprehensible algorithmic solution in base R that takes a few seconds to run but does the job. But at least with this solution I got to make a pheatmap I am immensely proud of.
Github
Another solution in F#: day05.fsx
Thought today's solution looked pretty clean. Regex for parsing the input, a HashMap for saving overlaps and a simple .scan() for generating the points.
Some really ugly C# solution
Python 3.8 solution This was difficult, I debugged for 2 hours to find out I wasn' counting the first time I encountered a diagonal... However I'm sattisfied, this is pretty quick
Clojure solution. I tried to refactor it so it's readable (I hope so). I also include a small write-up note.
PHP solution, also available on Github. It's not very optimal as far as memory consumption is concerned. The reason is that for a range of, for example, 1,1 => 4,4, it will allocate memory for four pairs. These might then get incremented if another line crosses either of the coordinates.
https://github.com/artesea/advent-of-code/blob/main/2021/05a.php%5D
F#, Readable single function to solve both parts, Learning F# so preferring strong types, use as much as in-built functions, and avoiding loops
challenge 2 execution time of ~0.4 seconds. I'll try better tomorrow
Part 1
Python 3 I used namedtuples and yield to keep things simpler. In the second part, it is so much easier to write if statements rather than trying to generalize the cases. https://github.com/EnisBerk/adventofcode/tree/master/day5
The full solution is on GitHub but the two key functions are:
But hey, it works. ¯\_(ツ)_/¯ https://github.com/ThePituLegend/advent-of-code-2021/tree/main/day5
Python no external libraries.
Love that I'm seeing more Kotlin, here's mine -- Kotlin Solution
My Python solution is on my GitHub Repo.
[GitHub](https://github.com/thedavecarroll/AdventOfCode/blob/main/2021/PowerShell/Day5.ipynb)
Nicer than my solution: rust
First 2D one! Got to reuse my InfiniteGrid class, which made this much easier.
PHP part one 26 lines
Here is my 🦀 Rust solution for the 🎄 AdventOfCode's Day 5: Hydrothermal Venture - Part 1: https://github.com/garciparedes/advent-of-code/blob/master/2021/05_hydrothermal_venture_part_1.rs - Part 2: https://github.com/garciparedes/advent-of-code/blob/master/2021/05_hydrothermal_venture_part_2.rs
Part 1, Part 2 , my notes.
Not nicest but learning Rust again, https://github.com/pavel1269/advent-of-code-2021/blob/main/src/day05/mod.rs . Simple solution using 2d vectors for the map, memory is cheap.
day 5 in repo
Path: Path.java Input Parser: PathInputParser.java
Link to the GitHub repo
Neat, our code is quite similar, though yours is far superior - love the Point class and use of the dataclass decorator. Stole use of Counter, which improved my runtime for part one by an embarrassing amount. https://github.com/americanhanko/advent-of-code-2021/blob/master/05/vents.py
Part 1 and part 2 are both very similar. I maintained an actual map of the vents in memory (it's less than a megabyte). I then drew either horizontal and vertical lines (for part one and two) and slope-up and slope-down diagonals (for part two alone) by incrementing the map wherever a vent appeared. This isn't safe if there's more than 255 intersections, but there weren't, so we're good. I could also have used a larger map if the number of intersections got too high.
You can find the whole thing here
I had to map everything to a class to understand what to do: [github]
GitHub/HydrothermalVentMapper.java
Javascript: https://github.com/etnichols/advent-of-code/tree/master/day5
Did two versions to compare Scala and Rust justinhj/adventofcode2021-day5 justinhj/adventofcode2021-day5-scala/
Did two versions to compare Scala and Rust justinhj/adventofcode2021-day5 justinhj/adventofcode2021-day5-scala/