My solutions for the Advent of Code 2021 in Scala, Python, Haskell and Rust.

Overview

Advent of Code 2021

These are my Advent of Code 2021 solutions written in Scala 3, Haskell, Python and Rust.

Day Title L1 L2 L3 L4
01 Sonar Sweep Scala Haskell Python Rust
02 Dive! Scala Haskell Python Rust
03 Binary Diagnostic Scala Haskell Python Rust
04 Giant Squid Scala Haskell Python Rust
05 Hydrotermal Venture Scala Haskell Python Rust
06 Lanternfish Scala Haskell Python Rust
07 The Treachery of Whales Scala Haskell Python Rust
08 Seven Segment Search Scala Haskell Python Rust
09 Smoke Basin Scala Haskell Python Rust
10 Syntax Scoring Scala Haskell Python Rust
11 Dumbo Octopus Scala Haskell Python Rust
12 Passage Pathing Scala Haskell Python Rust
13 Transparent Origami Scala Haskell Python Rust
14 Extended Polymerization Scala Haskell Python Rust
15 Chiton Scala Haskell Python Rust
16 Packet Decoder Scala Haskell Python Rust
17 Trick Shot Scala Haskell Python Rust
18 Snailfish Scala Haskell Python Rust
19 Beacon Scanner Scala Haskell Python Rust
20 Trench Map Scala Haskell Python Rust
21 Dirac Dice Haskell Python

Remarks

  • Scala solutions are short and concise, be sure to check them out.
  • The solutions are self contained, they can easily be executed as shown in the next section. This also makes them just a bit cluttered because the parsing and the part selection are inside the same file.
  • Both parts of each problem are solved in the same file, this requires a bit of generalization to solve both parts with almost the same code, and makes the code longer than other solutions.
  • These are not the shortest or fastest solutions, but they are readable and show the key ideas for solving each problem and how to translate them to each different language.
  • The Python solutions are a bit clunky because these are the ones I code first.
  • The solutions in Rust are not so good because this is the first time I use Rust for this kind of problems. It gets better day by day, but don't expect amazing code.

Running the solutions

The solutions are self-contained and should run easily using the appropriate interpreter/compiler for each language, keeping the following considerations in mind:

  • Input is taken from standard input.
  • Either 1 or 2 must be passed as arguments to choose which part to run.

Scala 3

For example, to run the Scala solution for the second part of the first day, you can use the following command:

cat day01/test01.txt | scala day01/Day01.scala 2

Haskell

The solutions were tested with GHC 9.0.1, but 8.x should work too. No other libraries apart from base, containers and mtl are used, they should be installed by default.

cat day01/test01.txt | runghc day01/Day01.hs 2

Python

The solutions were tested with python 3.9, but they should work using any version >=3.8. Only numpy is used apart from the standard library.

cat day01/test01.txt | python3 day01/Day01.py 2

Rust

To run a Rust solution you must compile it first and then run the resulting executable:

rustc day01/Day01.rs
cat day01/test01.txt | ./Day01 2
You might also like...
Advent of Code 2021, in rust this year

Advent of Code 2021 🎄 Solutions for the 2021 edition of Advent of Code. This year, I try to do this in Rust 🦀 . I discover the language, so do not t

My solution for the advent of code 2021, mainly written in Rust

Advent-of-Code-2021 My solution for the advent of code 2021, written in Rust Error Handle NOPE!!! unwrap() everything everywhere Use To run all of the

Quick'n dirty macro set for advent of code 2021

AOC quick'n dirty macro set Those are implemented using quick'n dirty procedural macros and libraries. Running the program Use cargo run --release --

🦀 Advent of Code 2021

Advent of Code 2021 License Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) MIT li

Advent of Code - 2021

Advent of Code - 2021 Solutions to the Advent of Code 2021 written in Rust using cargo-aoc. Instructions Install cargo-aoc with cargo install cargo-ao

Soluciones a los retos del Advent of Code 2021.

Advent of Code 2021 Soluciones a Advent of Code 2021. Repos de otros miembros de AoC Canarias: Ricardo Cárdenes Víctor Ruiz José Rodríguez Juan Ignaci

Advent of Code 2022 Solutions (in Rust)

Advent of Code 2022 My solutions for Advent of Code 2022, written in Rust. This repository provides a good template for anyone interested in writing t

My solutions for Advent of Code 2022, written in Rust

Template largely copied from RikvanToor/aoc-rust-template, upgraded for clap v4. This template can be forked/cloned from beeb/aoc-rust. Usage First, f

  🦀 Rust solutions for Advent of Code 2022
🦀 Rust solutions for Advent of Code 2022

🎄 Advent of Code 2022 Solutions for Advent of Code in Rust. 2022 Results Day Part 1 Part 2 Day 1 ⭐ ⭐ Day 2 ⭐ ⭐ Day 3 ⭐ ⭐ Day 4 ⭐ ⭐ Day 5 ⭐ ⭐ Day 6 ⭐

Owner
Axel Suárez
Axel Suárez
Advent of Code 2021 puzzles & solutions in Rust

Advent of Code 2021 These are puzzles for the Advent of Code 2021 challenge, written and solved in the Rust programming language. The puzzle for each

Chevy Ray Johnston 8 Dec 19, 2021
My solutions to Advent of Code 2021 (mostly in rust)

Advent of Code 2021 Small code to solve problems at https://adventofcode.com/2021. Most of the code are written in Rust. How to run solutions For exam

“Plane” Abhabongse  Janthong 3 Apr 22, 2022
🎄My Advent of Code 2021 solutions in the Rust programming language

Advent of Code 2021 in Rust My Advent of Code 2021 solutions in the Rust programming language. This repository holds a separate Rust project for each

Tim Visée 227 Dec 16, 2022
My solutions for Advent of Code 2021, in Rust

Advent of Code 2021 These are my solutions. I have decided to use Rust for now. I'm new to Rust, so it might be some of the worst Rust code you've see

Samyak Sarnayak 1 Jan 1, 2022
Solutions to Advent of Code 2021, coded in rust

Advent of Code 2021 (aoc-2021-rust) Solutions to Advent of Code 2021 (https://adventofcode.com/2021), coded as part of my efforts to learn Rust Run co

null 0 Dec 24, 2021
Repository with my Advent of Code 2021 puzzle solutions 🎄

?? Advent of Code 2021 ?? I decided to stick with Rust this year and try to improve a bit on it, I basically haven't used it since last year's AoC, so

fratorgano 2 Dec 1, 2022
⭐ Advent of Code 2021: Мade with Rust

Advent of Code 2021: Мade with Rust When I was solving puzzles, my goal was to practice writing idiomatic Rust. My solutions do not claim to be the fa

Sergey Grishakov 13 Dec 2, 2021
Advent of Code 2021 (Rust)

aoc-2021 Advent of Code 2021 with Rust. To build and run the project This project uses cargo-aoc. More detailed instructions can be found at that proj

Belén Albeza 13 Dec 23, 2021
Advent of Code 2021, also an attempt to practice a bit of Rust.

Advent of Code 2021 Advent of Code 2021 (my first one!), also an attempt to practice a bit of Rust. Running (Assuming that the respective inputs are i

Edoardo Debenedetti 1 Dec 3, 2021
Learning Rust through Advent of Code 2021 - probably not very clean!

AoC 2021 ======== I'm using AoC2021 as an excuse to learn Rust (and maybe some other languages). Please do *not* use this repository as a good source

Andrew Zhu 0 Dec 8, 2021