Our great sponsors
- Sonar - Write Clean Python Code. Always.
- InfluxDB - Access the most powerful time series database as a service
- ONLYOFFICE ONLYOFFICE Docs — document collaboration in your environment
-
If you are using custom Coord objects, you could consider going in and making a map of coord to value. Saves a bunch of boundaries checks, as you can see in zebalu's solution (another comment in thread) https://github.com/zebalu/advent-of-code-2021/blob/master/src/main/java/io/github/zebalu/aoc2021/Day09.java
-
Solution without cycle and solution with cycle are both at around ~300ms, same plans
-
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.
-
F#, learning F#, took some time to implement DFS, but happy with solution.
-
-
-
python 1016/334
-
Python 3 668 / 616
-
InfluxDB
Access the most powerful time series database as a service. Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.
-
-
adventofcode
Advent of Code solutions of 2015, 2016, 2017, 2018, 2019, 2020, 2021 and 2022 in Scala (by sim642)
My Scala solution.
-
advent-of-code-go
All 8 years of adventofcode.com solutions in Go/Golang; 2015 2016 2017 2018 2019 2020 2021 2022
-
Python
-
-
Python Using image libraries to not do any real work!
-
Go, 1730/3574
-
Part 1 nested ifs (does it count as "AI"?), Part 2 used DFS based on https://brilliant.org/wiki/depth-first-search-dfs/ solution in rust
-
Another fun one today!
-
-
-
-
Part 1 solutionPart 2 solution
-
Part 1
-
source code on GitHub as a notebook explaining the technique of using boolean masks with NumPy arrays.
-
That said, Day 9 in Go.
-
-
Common Lisp. Nothing special, just a BFS.
-
advent-of-code
Solutions for Advent of Code problems in various languages. (by Andrew-William-Smith)
This was a pretty fun day! I'm very glad that I took the time to write a small utility module for handling multidimensional arrays in Erlang a few days ago: otherwise, trying to wrestle coördinates would have quickly become painful. This was also my first time writing DFS in Erlang; a queue-based tail-recursive approach ended up being much cleaner than a simple recursive approach that used lists:foldl/3 to pass the modified matrix between neighbours. Writing the algorithm both was was definitely a great learning experience though!
-
TypeScript
-
-
my rust day9:
-
Did a recursive DFS to solve part 2. github code
-
rust solution part 2 bfs
-
-
-
Day9
-
Part1
-
After a bit of cleanup, mine is taking 230µs: https://github.com/MarcusTL12/AdventOfCode2021_Julia/blob/main/src/day9.jl
-
Part1 Part2
-
Raku 6832/4872. Despite being a highly-paid software professional I managed to implement three incorrect ways to get the four adjacent grid cells. This is now the second problem this year where I've unnecessarily handled diagonals.
-
Solved part2 using bfs: y2021/day_09.ex
-
-
ts (deno) https://github.com/jackysee/aoc/blob/main/2021/day9.ts ` import data from './day9_input.ts';
-
So much more elegant than my solution
-
-
-
-
Python source
-
Part 1 involved reading the map and searching for low points. I used border cells to avoid having to check boundaries.
-
Mine runs in 130us (without the time spent in parsing the input) But the time will vary between the machines :)
-
Easy to understand JavaScript solution on https://github.com/northflank/adventofcode2021/blob/main/day9.js
-
Python 3 Ah.. good old recursion in this one :) More a "flow up" than a "flow down". Still learning Python and open to suggestions. Solution A & B
-
part1 with window functions: https://explain.dalibo.com/plan/drW
-
Solution in Python
-
presenting the worst code I have written in my life, including in high school (here, in Ruby)
-
-
python solutiuon
-
Solution
-
My solution in Rust looks rather straightforward: the first part initalizes lower points and then the second runs BFS over them.
-
-
Github
-
TypeScript, with a recursive Flood Fill algorithm for part 2: https://github.com/eszpee/adventofcode2021/blob/main/src/day09.ts
-
Today was very enjoyable, albeit a bit easier than expected after what was yesterday, haha. Part1 and part2 in Javascript
-
Haskell 1848/1580
-
For part 2, instead of trying to union-merge from the lowest points, I simply found all connected regions of <9. I say "simply" because I just threw things at fgl, but setting the graph up first took a bit of work. buildGr is fast but picky about the exact order things come in with.
-
Python
-
- C -
-
Advent-of-Code-2021
Made it through all 25 days of Advent of Code for the second time! (by Leftfish)
Figuring out that part 2 was essentially the 'find islands in a 2d matrix' problem was the easy thing. Remembering how to implement a DFS or BFS was another story. So I ended up implementing both for learning purposes (Python).
-
code on github
-
Haskell
-
Kotlin solution, probably not the most efficient but does the job.
-
Solution in Javascript, messy part1, nice multi recursions for part 2
-
-
Python 3 solution (Github link) with only standard libraries. Runs both halves individually in 0.02s total.
-
Rust: https://github.com/cadubentzen/advent-of-code-2021-rs/blob/master/src/bin/day09.rs
-
-
-
Elixir. Simple Union-Find via reducing maps to themselves.
-
-
-
-
-
-
-
Full code here
-
-
Had a headache with part two, thinking that adjacent values had to be consecutive. It just needed to be less. Javascript solution
-
-
Clojure/Racket
-
-
This was one of those few times where I was pretty happy with what I wrote the first time through.
-
-
-
-
Python, using numpy for part 1 and scipy for part 2: https://github.com/harry-gibson/advent-of-code-2021/blob/main/day_09/day_09.py
-
C#: https://github.com/mohammedsouleymane/AdventOfCode2021/blob/master/AdventOfCode2021/Day9.cs
-
A solution in Rust.
-
C# solution, simple flood-fill type algo. I found a use for C# 9.0's record types, explained in the blurb at the top of the file
-
-
Solution for today in Common LISP.
-
Solution (ammonite) - Couldn't do this without recursion and an immutable map without blowing up the heap.
-
Rust
-
You don’t necessarily need to use recursion (which I also suck at implementing). Here’s my iterative version: https://github.com/jslepicka/aoc2021/blob/master/9.py
-
For the full implementation, see my code here.
-
-
-
-
PHP solution, simple DFS for part 2 :
-
Day 9 using python
-
-
Full version here
-
# [JQ](https://github.com/odnoletkov/advent-of-code-jq) [ [inputs/"" | map(tonumber)] | . as $map | (range(length) | [.]) + (range(first | length) | [.]) | select( [ ., first += 1, first -= 1, last += 1, last -= 1 | select(all(. >= 0)) | $map[first][last] // empty ] | select(first == min and first != .[1]) ) | [ recurse( . as [$y, $x] | first += 1, first -= 1, last += 1, last -= 1 | select(all(. >= 0) and ($map[first][last] | . < 9 and . > $map[$y][$x])) ) ] | unique | length ] | sort[-3:] | .[0] * .[1] * .[2]
-
-
adventofcode
My collection of Advent of Code solutions in a slightly overkill project setup 🙃👻 (by marcelblijleven)
-
Cheating a bit, by using my existing AOC library for handling of 2D maps. Made the overall code fairly straightforward:
-
F#: https://github.com/spencerwi/AdventOfCode2021/blob/main/day9/Program.fs
-
-
My solutions in my git repository => Git And you can try it online at => Stackblitz
-
Pascal 2437/6187
-
-
-
GitHub link for code
-
Rust. I took a somewhat different approach to filling the basins. Each one is “named” and grows on each iteration through https://github.com/abaptist-ocient/Aoc2021/blob/main/src/bin/09.rs
-
https://github.com/willkill07/AdventOfCode2021/blob/main/days/Day09.hpp https://github.com/willkill07/AdventOfCode2021/blob/main/days/Day09.cpp
-
-
JavaScript - Part 1 and Part 2, each with comments.
-
My first solution had a brute-force search for minimum points, and a BFS to find the basins (https://github.com/brett-lempereur/aoc-2021/blob/main/day-9/solution.rkt).
-
GitHub Solution
-
Fun one! Got it fairly compact in rust (part 1 & 2).
-
Github
-
Kotlin solution with some recursion on Part 2. Fast, but feels clunky to me. Like I could've slimmed it down. Open to suggestions. Nice problem overall, though! :)
-
-
-
Part 2 (extract shown below) was a matter of starting with the low points found in part 1 then recursively looking around for relevant points. Full code on GitHub
-
-
Lua https://github.com/mrbuds/adventofcode2021/blob/main/9-2.lua
-
Python
-
Code can be found in this repo.
-
-
aoc2021
I will be trying the this years Advent of Code. I am unsure of what language I will be using. Let's see how this goes. (by jtagrgh)
Pt 1: https://github.com/jtagrgh/aoc2021/blob/main/day9-smoke-basin/pt1.c
-
F# with Jupyter Notebook. I had a hard time wrapping my head around the recursion on this one for Part 2. Got some helpful tips on the sub-reddit!
-
Clojure, source and tests. Part 1 was simple but I couldn't get anything going for part 2 after a couple of hours. I initially tried a naive DFS approach (which I know essentially nothing about) but wasn't successful in constructing a tree from a low point.
-
-
After some serious de-spaghettification: R / Rstats
-
-
Finally managed to solve Part 02 in Python. I was stuck because I could not figure out a way to go through all the points around a low point till I got to a 9. Then yesterday I say u/skarlso's post about Red Blob games and the various pathing algorithms, and the breadth-first-search example just unblocked the whole solution for me. :)
-
github
-
-
-
part 1 part 2
-
PHP
-
AdventOfCode2021
Advent of Code 2021 challenge: 13 different languages, one chosen at random every day! (by Qualia91)
-
ONLYOFFICE
ONLYOFFICE Docs — document collaboration in your environment. Powerful document editing and collaboration in your app or environment. Ultimate security, API and 30+ ready connectors, SaaS or on-premises