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.
-
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.
-
AdventOfCode
My Advent of Code solutions. I also upload videos of my solves: https://www.youtube.com/channel/UCuWLIm0l4sDpEe28t41WITA
-
AdventOfCode2021
Solutions to all 25 AoC 2021 problems in Rust :crab: Less than 100 lines per day and under 1 second total execution time! :christmas_tree:
-
advent-of-code-go
All 8 years of adventofcode.com solutions in Go/Golang; 2015 2016 2017 2018 2019 2020 2021 2022
-
adventofcode
Advent of Code solutions of 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 and 2023 in Scala (by sim642)
-
programming-challenges
My attempts at solving various programming challenges. Leetcode, codewars, adventofcode, etc (by x-zvf)
-
advent-of-code
(Work in progress) Python solutions for Advent of Code programming puzzles. (by fedecalendino)
-
adventofcode2021
Discontinued Advent of Code 2021 [Moved to: https://github.com/thecircleisround/adventofcode] (by thecircleisround)
-
AdventOfCode2021
A collection for my Advent of Code (www.adventofcode.com) solutions using Nim, Julia, and Python programming languages (by genius487)
-
advent-of-code
My Python 3 solutions for Advent of Code® with an emphasis on beautiful code (by bsoyka)
-
Advent-of-Code-2021
My bros got chocc calendars and I didn't (sad) so I have to eat code for krismas every day. (by dziobex)
-
advent-of-code-2021
Discontinued Trying to solve https://adventofcode.com/ [Moved to: https://github.com/ThePituLegend/advent-of-code] (by ThePituLegend)
-
aoc_ts
Discontinued 🎄 Advent of code solutions written in TypeScript for Deno. [Moved to: https://github.com/N8Brooks/deno_aoc]
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
here is full source
I first did id in plain Nim but I wished I was doing it in Python's numpy. Than I remebered I heard about a similar project for Nim and so I'm learning arraymancer now:
Python implementation on GitHub
Kotlin solution for Day 4, leverages OOO a lot.
My solution in rust. Performance as reported by the criterion benchmark:
My repo can be found here, if you're curious =)
Exploding and giving coordinates number to everything is actually the road I have chosen here. It's a bit more cumbersome at first, but the rest is very idiomatic sql (in my opinion). (my solutions are here if you're curious)
So far my favorite sql solution is this one: https://gitlab.com/feike/adventofcode/-/blob/master/2021/day04/04-2.sql
TypeScript Solution, under 50 lines, single function for both the parts.
My cpp solution: https://github.com/giorgosioak/aoc-21/tree/main/04
Python p1 & p2, I was really happy with my approach initially but then I kinda screwed the pouch while using dictionaries. Overall it was kinda fun.
Python. 30th on part 1; 15th on part 2. Video of me solving.
python 372/225
Rust -- Happy with how my code turned out for today. I used nalgebra's Matrix5 for storing the boards, which made checking for wins pretty easy.
Go, 1437 / 1664
My Ruby solution
Python 3 724/655
Python 3, with numpy.
python3
TypeScript and Lodash https://github.com/AlmogAdziashvili/Advent-of-Code-2021/blob/master/days/4/solve.ts
TypeScript and Lodash https://github.com/AlmogAdziashvili/Advent-of-Code-2021/blob/master/days/4/solve.ts
Messy; misreading the directions caused me to scramble. I'll try to clean this up and maybe make it more efficient in the morning
Python 3.7 (652/709)
oK
Link to full solution
github
Solution in Go: https://github.com/alexchao26/advent-of-code-go/blob/main/2021/day04/main.go
Python: https://github.com/bennuttall/advent-of-code-2021/blob/main/04/04.ipynb
GitHub
https://github.com/jackdreilly/aoc2021/blob/main/d4b.py Immutable recursive approach, using cached_property and dataclasses for readability and sanity
Python 3 using numpy and sets https://github.com/moprak/aventofcode/blob/master/2021/4.py. Notes: 1) I really should internalize zip(*board) for the transpose, but numpy makes things easy enough.
C++ Part 1 and Part 2
Common Lisp.
georgiee/advent-of-code-2021/day-04 (GitHub)
Python solutions
My Rust (github) solution.
common lisp
Raku
Would love some feedback on my board implementation if anyone has the time. Or, specifically, my has_bingo method below. Is there a better way to check for bingo?
My Scala solution.
Python3 and NumPy, without modifying the boards in memory.
Helper functions parse_input(), and Board::numbers_to_win(), checksum() are in here to avoid creating a wall of text.
Nasty C# with Linq
Pretty happy with this one ``` def solve() -> List[int]: seen = [] won = [] scores = [] for n in NUMS: seen.append(n) for board in BOARDS: transpose = list(zip(*board)) for i, line in enumerate(board): if (all(num in seen for num in line) or all(num in seen for num in transpose[i])) and board not in won: won.append(board) scores.append(sum(sum(num for num in line if num not in seen) for line in board) * seen[-1]) return scores
A simple iterative approach in python :)
It's way messier than I hoped. Javascript solution
Rust
Python
PYTHON. I did first version without Numpy but decided that its way too useful so I did some refactoring and below is my solution. It's a bit slow so not the most optimal.
C++ solution using Eigen: github
I just looked up https://codewithrockstar.com/ and absolutely lost it at "Tommy used to work on the docs."
Using Linq and AoCHelper. See full code here.
Part1: https://github.com/jameshoffmann/aoc2021/blob/main/day4/part1.js
link
full source code with imports and type annotations
Clojure, using (almost) exclusively set logic. Looking at the other solutions, it could have probably been simplified, but I'm somehow compelled to use sets whenever I get the chance.
Haskell 7093/6593
Haskell A bit verbose, but I think a quite readable and clean solution: https://github.com/Petrosz007/advent-of-code/blob/master/2021/day-4/day4hs/Day4.hs
C, which takes some bookkeeping but it can be fast. I didn't push for every last drop of speed but still: about 3 ms on a Raspberry Pi 4 (1.8 GHz overclock, Buster desktop, not very quiet so I picked a good run). Code with lots of comments
https://github.com/justme789/Advent_of_Code_2021_Solutions_Java/
Using Rust - my day 4 solution here
A functional Scala solution using tail recursion. Most of the code is setting up case classes and parsing the input, the actual "business logic" is fairly concise, imo.
Part 1: https://github.com/xBracey/adventofcode2021/blob/main/src/day4/index.ts Part 2: https://github.com/xBracey/adventofcode2021/blob/main/src/day4/part2.ts
Part 1 (GitHub) Part 2 (GitHub)
Part 1: https://github.com/Charlesworth/adventOfCode2021/blob/main/typescript/day4/part1.ts Part 2: https://github.com/Charlesworth/adventOfCode2021/blob/main/typescript/day4/part2.ts
I don't know what you think about using external libraries, but you can avoid lots of double for loops if you represent the board, and the matche,s as numpy arrays. Here is some of my code. https://github.com/oli5679/advent-of-code/blob/master/2021/04.ipynb
(CSpydr is my own programming language written in pure C)
I made a stateless solution, with the board a List[List[Int]].
full solution
My solution in Python, using a stateful approach that amounts to object-oriented programming.
🐍️ solution
Rust, nothing fancy.
GitHub
Source Code
Github code
Day 4 Code
Elixir
Scala 3
C# - Parts 1 & 2 The second part was surprisingly short, copy paste of P1 but just had to change an if statement in the final for loop.
Go
Python
day four sollution
C# coming through here: https://github.com/kemmel-dev/AdventOfCode2021https://github.com/kemmel-dev/AdventOfCode2021/blob/master/day4/AoCDay4/AoCDay4/Program.cs
Python
Haven't seen any Swift solutions so far this year, so here's my attempt: https://github.com/gereons/AoC2021/blob/main/Sources/AdventOfCode/puzzle4.swift
Here's a C++ solution.
Part 1: https://github.com/Sebbern/Advent-of-Code/blob/master/2021/day04/day04.py
Part 1 and 2 in Haskell. About 30 lines of code
Python with OOP and lots of comments (both parts)
Kotlin Solution / KoTest Tests
Main Code: Day4.java
[Nim](https://github.com/genius487/AdventOfCode2021/blob/main/day04/n21d04.nim), [Python](https://github.com/genius487/AdventOfCode2021/blob/main/day04/p21d04.py), [Julia](https://github.com/genius487/AdventOfCode2021/blob/main/day04/j21d04.jl)
python3 with numpy
Doing this for the first time, in Ruby (still learning the language, code likely reflects that)
Part 1: https://github.com/SV-97/AdventOfCode2021/blob/main/Day_04_1/main.py
Python 3
Full code with the omitted parsing logic etc - https://github.com/ethsgo/aoc/blob/main/js/_04.js
PHP
Part 2 0.226ms
Did some nice Python OOP! Split into three files, part 1, part 2, and shared classes.
As a side note, I took inspiration from a post the other day about adding AoC badges to your repository README file. I use GitLab, which lets you define badges as properties of your repository. So I added badges to my repository's header area, driven by a JSON file in the repository. The JSON file is updated manually by a script. (I might add some automated updates at some point, but manual works okay for now.)
Python solution day 4 OOP (GitHub). Probably not the fewest lines of code but uses dataclasses and OOP to manage the states of each bingo card
My solution in Kotlin, using only immutable data, functional constructs and tail recursion. I'm sure any functional programming and algorithm expert could do this with less lines of code, but I'm happy with the result: https://github.com/Tohnmeister/advent-of-code-2021/blob/main/src/main/kotlin/nl/tonni/adventofcode2021/Day4.kt
Finally got around to do today's puzzle - F#: day04.fsx
also all of my solutions avaliable on my github adventofcode
solution at github
Common Lisp https://github.com/sjl/advent/blob/master/src/2021/days/day-04.lisp
Github
Rust
Github
My Clojure solution. I also have a little write-up for solving the problem.
Clojure, source and tests. Any feedback welcome!
[GitHub Solution](https://github.com/daniel-meilak/Advent-of-Code-2021/blob/main/week_1/day_4/day_4.cpp)
Python!
C# Part 1 and 2
Solution
C++
Haven’t seen a lot of JavaScript in here, so here’s mine: https://github.com/DanFessler/advent-of-code/tree/master/2021/04
Rust https://github.com/Crazytieguy/advent-2021/blob/master/src/bin/day4/main.rs
https://github.com/adarsh0d/advent-of-code-2021/blob/master/day4/day4.js - feels suboptimal, but I got right answer
C++ Parts 1 & 2
Day 1 was 10 LOC, each day is adding about 10 LOC, so now I'm at 40. I don't like where this is heading. https://github.com/einarjon/adventofcode.sh/blob/main/2021/04.sh Small mistake in Part 2 so it starts the bingo from the beginning, but the first numbers are crossed out. Doesn't affect the result.
GitHub link: https://github.com/brett-lempereur/aoc-2021/blob/main/day-4/solution.rkt
I used a BingoDrawing grammar to parse the numbers and cards, and BingoCard and BingoGame classes to implement the Bingo game. Code is much too long to include in a comment, so see GitHub.
Python OO I forgot to reset the boards for the second part, check it out yourself if you are having a problem. https://github.com/EnisBerk/adventofcode/blob/master/day4/main.py
Solution in Javascript, fully functional with a bit of recursion
Rust: Ouch, this one is slow https://github.com/jeremylt/advent2021/blob/main/src/day04.rs 552.623µs (Std Dev 32.275) locally, repl currently has some issue with an older version of Rust, so timings are WIP
fun problem, but my worst solution. for loops overload: https://github.com/rbusquet/advent-of-code/blob/main/2021/04/day4.py
Python 3.10 Solution A & B Open to any suggestions, still learning Python. Could probably change the two for loops in the actual solution into a list comprehension to generate a list of completions and their scores...
A fairly terse python solution (21 lines): https://github.com/MagicLemma/advent-of-code-2021/blob/main/day4.py
Here's my solution:https://github.com/mrisoli/adventofcode/blob/master/python/2021/d4.py
Day 04 Code
Python using numpy: https://github.com/Limeman/advent_of_code/blob/master/day_4/part_2.py
thanks - used your `nalgebra` tip for my solution :) https://github.com/dmitris/adventofcode-2021/blob/main/day04/src/main.rs
Python 3.8 solution Choosing the right Data structure can be life saving.
Solution for both parts
Here’s my Ruby solution: https://github.com/poblouin/advent-of-code-2021/blob/main/04/solution.rb
Java: https://github.com/jaredculp/aoc2021/commit/d9ba191cda3595a9b7206bb6b1a89a2e700f947c
I enjoyed today’s. More fun with the Pointfree swift parsing and overture libraries. Trying to improve my functional programming chops a bit. https://github.com/lukeredpath/AdventOfCode2021/blob/main/Sources/AdventOfCode2021/04.swift
Here is the formated code. There are the puzzles input also, the true one and the example. If you find where I failed, I owe you one!
C# GitHub
R / Rstats: Code
Python 3.8, classes approach: https://github.com/deshudiosh/AdventOfCode2021/blob/master/day04/day04.py
C++
This was one of those instances when the solution to part 1 could be mostly used for part 2. I just had to delay returning the result until the list of winners so far matched the number of boards. So I'll show part 2 only but both solutions are on GitHub.
Elixir
challenge 2 I'm sorry
repo
github
This one kicked my ass for a while, which was confusing because the tests all passed fine with example data. Eventually I tracked down the problem to the way I was reading in the actual puzzle input... I should've known. Anyway, in addition to the [Github repo](https://github.com/krmaxwell/aoc2021/master/day4] with full tests and stuff, here's the core answer:
Python with no external libraries and C++ Python C++
Go day 4: GitHub
Go / Golang Tutorial Blog Post.
python p1 & p2: https://github.com/jabadia/advent-of-code-2021/tree/main/d04
Completed with no external libs, no if statements and to much free time this weekend https://github.com/emilbratt/adventofcode/tree/main/2021/4
not my proudest C# solution
I've been writing the parsing functions in a utility library for Advent of Code as I worked through all of the stars. The parser is here https://github.com/blake-watkins/advent-of-code/blob/main/parser.lisp
Rust, Part 1 and 2
Here's the code for Part 1 and 2, along with my notes while I was coding.
Though I've been doing this year in F#, I decided to give parallelism in C# (my "native tongue", if you will) a go in day four, just to see if it made a significant difference.
Part 1 was fairly nice, but I did need to write several functions to check if a board won.
BoardNumber BingoBoard Day04of2021
I have two files: day_4.rb for the Game class. It has some methods and etc. for the game. Run this file for the result! board.rb for the Board class. It's for handling a board.