ggzor/advent-of-code-2021
My solutions for the Advent of Code 2021 in Scala, Python, Haskell and Rust.
{ "createdAt": "2021-12-03T01:45:27Z", "defaultBranch": "main", "description": "My solutions for the Advent of Code 2021 in Scala, Python, Haskell and Rust.", "fullName": "ggzor/advent-of-code-2021", "homepage": "", "language": "Rust", "name": "advent-of-code-2021", "pushedAt": "2022-05-18T18:59:29Z", "stargazersCount": 2, "topics": [ "advent-of-code", "advent-of-code-2021", "haskell", "polyglot", "python", "rust", "scala" ], "updatedAt": "2022-10-14T06:52:44Z", "url": "https://github.com/ggzor/advent-of-code-2021"}Advent of Code 2021
Section titled “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]!(day01/Day01.scala) | [Haskell]!(day01/Day01.hs#L5-L9) | [Python]!(day01/Day01.py) | [Rust]!(day01/Day01.rs) |
| 02 | Dive! | [Scala]!(day02/Day02.scala) | [Haskell]!(day02/Day02.hs#L7-L35) | [Python]!(day02/Day02.py) | [Rust]!(day02/Day02.rs) |
| 03 | Binary Diagnostic | [Scala]!(day03/Day03.scala) | [Haskell]!(day03/Day03.hs#L9-L41) | [Python]!(day03/Day03.py) | [Rust]!(day03/Day03.rs) |
| 04 | Giant Squid | [Scala]!(day04/Day04.scala) | [Haskell]!(day04/Day04.hs) | [Python]!(day04/Day04.py) | [Rust]!(day04/Day04.rs) |
| 05 | Hydrotermal Venture | [Scala]!(day05/Day05.scala) | [Haskell]!(day05/Day05.hs#L11-L30) | [Python]!(day05/Day05.py) | [Rust]!(day05/Day05.rs) |
| 06 | Lanternfish | [Scala]!(day06/Day06.scala) | [Haskell]!(day06/Day06.hs#L13-L29) | [Python]!(day06/Day06.py) | [Rust]!(day06/Day06.rs) |
| 07 | The Treachery of Whales | [Scala]!(day07/Day07.scala) | [Haskell]!(day07/Day07.hs#L10-L17) | [Python]!(day07/Day07.py) | [Rust]!(day07/Day07.rs) |
| 08 | Seven Segment Search | [Scala]!(day08/Day08.scala) | [Haskell]!(day08/Day08.hs) | [Python]!(day08/Day08.py) | [Rust]!(day08/Day08.rs) |
| 09 | Smoke Basin | [Scala]!(day09/Day09.scala) | [Haskell]!(day09/Day09.hs) | [Python]!(day09/Day09.py) | [Rust]!(day09/Day09.rs) |
| 10 | Syntax Scoring | [Scala]!(day10/Day10.scala) | [Haskell]!(day10/Day10.hs#L7-L41) | [Python]!(day10/Day10.py) | [Rust]!(day10/Day10.rs) |
| 11 | Dumbo Octopus | [Scala]!(day11/Day11.scala) | [Haskell]!(day11/Day11.hs) | [Python]!(day11/Day11.py) | [Rust]!(day11/Day11.rs) |
| 12 | Passage Pathing | [Scala]!(day12/Day12.scala) | [Haskell]!(day12/Day12.hs) | [Python]!(day12/Day12.py) | [Rust]!(day12/Day12.rs) |
| 13 | Transparent Origami | [Scala]!(day13/Day13.scala) | [Haskell]!(day13/Day13.hs) | [Python]!(day13/Day13.py) | [Rust]!(day13/Day13.rs) |
| 14 | Extended Polymerization | [Scala]!(day14/Day14.scala) | [Haskell]!(day14/Day14.hs) | [Python]!(day14/Day14.py) | [Rust]!(day14/Day14.rs) |
| 15 | Chiton | [Scala]!(day15/Day15.scala) | [Haskell]!(day15/Day15.hs) | [Python]!(day15/Day15.py) | [Rust]!(day15/Day15.rs) |
| 16 | Packet Decoder | [Scala]!(day16/Day16.scala) | [Haskell]!(day16/Day16.hs) | [Python]!(day16/Day16.py) | [Rust]!(day16/Day16.rs) |
| 17 | Trick Shot | [Scala]!(day17/Day17.scala) | [Haskell]!(day17/Day17.hs) | [Python]!(day17/Day17.py) | [Rust]!(day17/Day17.rs) |
| 18 | Snailfish | [Scala]!(day18/Day18.scala) | [Haskell]!(day18/Day18.hs) | [Python]!(day18/Day18.py) | [Rust]!(day18/Day18.rs) |
| 19 | Beacon Scanner | [Scala]!(day19/Day19.scala) | [Haskell]!(day19/Day19.hs) | [Python]!(day19/Day19.py) | [Rust]!(day19/Day19.rs) |
| 20 | Trench Map | [Scala]!(day20/Day20.scala) | [Haskell]!(day20/Day20.hs) | [Python]!(day20/Day20.py) | [Rust]!(day20/Day20.rs) |
| 21 | Dirac Dice | [Scala]!(day21/Day21.scala) | [Haskell]!(day21/Day21.hs) | [Python]!(day21/Day21.py) | [Rust]!(day21/Day21.rs) |
| 22 | Reactor Reboot | [Scala]!(day22/Day22.scala) | [Haskell]!(day22/Day22.hs) | [Python]!(day22/Day22.py) | [Rust]!(day22/Day22.rs) |
| 23 | Amphipod | [Scala]!(day23/Day23.scala) | [Haskell]!(day23/Day23.hs) | [Python]!(day23/Day23.py) | [Rust]!(day23/Day23.rs) |
| 24 | Arithmetic Logic Unit | [Python]!(day24/Day24.py) | |||
| 25 | Sea Cucumber | [Scala]!(day25/Day25.scala) | [Haskell]!(day25/Day25.hs) | [Python]!(day25/Day25.py) | [Rust]!(day25/Day25.rs) |
Remarks
Section titled “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]!(#running-the-solutions). 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
Section titled “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
1or2must be passed as arguments to choose which part to run.
Scala 3
Section titled “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 2Haskell (>= 8.10)
Section titled “Haskell (>= 8.10)”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 2Python (>= 3.8)
Section titled “Python (>= 3.8)”Only numpy is used apart from the standard library.
cat day01/test01.txt | python3 day01/Day01.py 2Rust (nightly >=1.62)
Section titled “Rust (nightly >=1.62)”To run a Rust solution you must first compile it and then run the resulting executable:
rustc day01/Day01.rscat day01/test01.txt | ./Day01 2