AdventOfCode2020
Solving Advent of Code 2020, each day in a different language
Install / Use
/learn @bereal/AdventOfCode2020README
Advent of Code 2020 - Polyglot Edition
This year I all of a sudden got an idea of trying to solve the Advent of Code challenge in 25 different languages. I didn't know that few people already did or tried to do this before. Below are the rants about my experience with each of the languages I chose.
Few generic consideration:
- it makes sense to start with the languages you're familiar the least, because the task complexity tends to grow
- some languages are better for some puzzles due to their features
- the goal is not just solve the puzzle, but to get the sense of the language and try to write idiomatic code
- extra points for reaching the maximum logic reuse between the 2 parts of each puzzle
I estimated my knowledge of each language by 0 to 4 scale, roughly meaning:
- 0: little to no knowledge
- 1: did something small occasionally
- 2: spent some time using or deliberately learning it
- 3: used at work before, but time passes
- 4: full proficency
Other People's Attempts
- Rog3rSm1th (AoC 2015, done in 2021)
- Chris Penner (2015 and 2016, a collective effort)
- Izzy Miller (2016)
- Thomas ten Katte (2016)
- Thomas ten Katte (2017, without repeating languages from 2016, so that's 50!)
- Benjamin Kraft (2017)
- Oleg Yamnikov (2017)
- Bert Peters (2017)
- Laurence Woodman (2018)
- Roza Gutiérrez (2019)
- Ágocsi-Kiss Bence (2020)
- MisterInSayne (2020)
- Will Killian (2020)
- Justin Hill (2020)
- Laurens Duijvesteijn (2020)
- Tsoding (2020, with live streaming)
- Jan Likar (2022)
- Thomas Kellermeier (2022)
- Ryan Beltran (2023, languages are in alphabetical order!)
Languages
| Day | Language | Knowledge | Puzzle | Solution | | --- | --- | --- | --- | --- | | 1 | Erlang | 2 | Report Repair | Link | | 2 | Prolog | 1 | Password Philosophy | Link | | 3 | Clojure | 2 | Toboggan Trajectory | Link | | 4 | AWK | 1 | Password Processing | Link | | 5 | Z80 assembly | 1 | Binary Boarding | Link | | 6 | Nim | 0 | Custom Customs | Link | | 7 | Raku | 0 | Handy Haversack | Link | | 8 | F# | 0 | Handheld Halting | Link | | 9 | Pascal | 2 | Encoding Error | Link | | 10 | Factor | 0 | Adapter Array | Link | | 11 | x86 assembly | 1 | Seating System | Link | | 12 | Ruby | 1 | Rain Risk | Link | | 13 | Julia | 0 | Shuttle Search | Link | | 14 | Rust | 1 | Docking Data | Link | | 15 | Scratch | 1 | Rambunctious Recitation | Link | | 16 | C++ | 3 | Ticket Translation | Link | | 17 | Haskell | 2 | Conway Cubes | Link | | 18 | C | 2 | Operation Order | Link | | 19 | JavaScript | 4 | Monster Messages | Link | | 20 | Scala | 1 | Jurassic Jigsaw | Link | | 21 | Dart | 2 | Allergen Assessment | Link | | 22 | Elixir | 0 | Crab Combat | Link | | 23 | Go | 4 | Crab Cups | Link | | 24 | Zig | 0 | Lobby Layout | Link | | 25 | Octave | 0 | Combo Breaker | Link |
Day 1: Erlang
Site: https://erlang.org
Knowledge: 2
Puzzle: Report Repair. Finding numbers with the given sum in a list.
I don't really know why I chose it for the first day, just something that came to my mind first. Solving simple puzzles in Erlang may be an enternaining and useful exercise, but they don't demonstrate the reason it exists well. Erlang was created to develop huge distributed telecommunication system, so the language itself is just an interface to the powerful virtual machine. Outside of the context when you need to handle 100500 kilorequests per millisecond and handle nuclear explosions in the datacenter gracefully it looks like an old dynamically-typed functional language with weird Prolog-like syntax. Which it is, but I still like it, and it matches the day 1 puzzle just well. Unfortunately, I've never had a real use case for it.
As for the puzzle, it can be brute-forced, but the recursive search can be way faster if the array is sorted beforehand.
Day 2: Prolog
Site: https://www.swi-prolog.org/ (the implementation I used)
Knowledge: 1
Puzzle: Password Philosophy. Match strings against the rules.
Prolog is one of the languages they taught is in the Uni and since then I tried to use it for some small projects. Still, the paradigm shift from function calling to pattern matching is challenging every time. A very nice brain exercise. The puzzle had to do with validating the passwords according to certain rules, and pattern matching is a great tool for such tasks.
Day 3: Clojure
Site: https://clojure.org/
Knowledge: 2
Puzzle: Toboggan Trajectory. Traverse a two-dimensional array according to the rules.
I'm in love-hate relations with Clojure. I love it when I write, and I hate it when I have to read it.
In this particular puzzle Clojure's coolest features, such as persistent data structures, concurrency abstractions,
metaprogramming etc cannot be demonstrated. But loop-recur and short #(...)-lambda syntax are cool.
Day 4: AWK
Site: http://www.awklang.org/
Knowledge: 1
Puzzle: Password Processing. Validate strings with fields.
AWK is a small DSL language whose main habitat is between the pipes in text-processing one-liners. So I decided it was worth trying to pay it some respect by writing more than one line for a change. Worked just fine and easy, though I am not sure how idiomatic is the code.
Day 5: Z80 assembly
Site: https://esolangs.org/wiki/Z80golf (the emulator I used)
Knowledge: 1
Puzzle: Binary Boarding. Decode ticket numbers and find a vacant seat.
ZX-Spectrum was my first computer and I still spend some time watching other people streaming games on it. I have not touched Z80 assembly since I was 15, so when I saw an easy to use Z80 emulation, I just had to try it. It was luck that this puzzle was essentially about binary numbers processing, and I am sort of proud to have squeezed the core solution in less than 60 lines of assembly code. 40 more lines are printing the result as decimals, which I mostly copy-pasted. An oh my I completely forgot how limited the instruction set is.
Day 6: Nim
Site: https://nim-lang.org/
Knowledge: 0
Puzzle: Custom Customs. Unions and intersections of sets.
Disclaimer: I had no idea about Nim before and this is going to be a subjective first impression. I realize, that most of the features that Nim advertises cannot appear in a 50-lines snippe
