blu3r4y / AdventOfLanguages2020

Solutions for the AoC 2020, written in 25 different programming languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advent of Languages 2020

πŸ’” πŸ–€ πŸ’› 🧑 πŸ’œ πŸ’™ πŸ’š ❀️

Solutions for the AoC 2020 puzzles, written in 25 different programming languages.

  • πŸ’” Assembly Languages
  • πŸ–€ Shell Scripting Languages
  • πŸ’› Database Languages
  • 🧑 Mathematical Languages
  • πŸ’œ Functional Languages
  • πŸ’™ System Programming Languages
  • πŸ’š Web Application Languages
  • ❀️ General-Purpose Languages

Solutions

Day Puzzle Language Reference Solution
1 Report Repair πŸ’” x86-32 day1.py   day1.s
2 Password Philosophy πŸ–€ Bash day2.py   day2.sh
3 Toboggan Trajectory πŸ–€ PowerShell day3.py   day3.ps1
4 Passport Processing πŸ’› PostgreSQL day4.py   day4.sql
5 Binary Boarding 🧑 Prolog day5.py   day5.pl
6 Custom Customs 🧑 Octave day6.py   day6.m
7 Handy Haversacks 🧑 R day7.py   day7.R
8 Handheld Halting πŸ’œ Haskell day8.py   day8.hs
9 Encoding Error πŸ’œ F# day9.py   day9.fsx
10 Adapter Array πŸ’œ Scala day10.py   day10.scala
11 Seating System πŸ’™ Nim day11.py   day11.nim
12 Rain Risk πŸ’™ C day12.py   day12.c
13 Shuttle Search πŸ’™ C++ day13.py   day13.cpp
14 Docking Data πŸ’™ Go day14.py   day14.go
15 Rambunctious Recitation πŸ’™ Rust day15.py   day15.rs

Usage

Instead of installing 25 toolchains, simply run each solution with Docker

export DAY=1
docker build -f ./docker/day${DAY}/Dockerfile -t day${DAY} .
docker run --rm -it day${DAY}

Input files must have LF line endings, which should be the default on checkout, if not, fix that with

dos2unix data/*.txt

License

Solutions are licensed under MIT. File icons are licensed under CC BY-SA 4.0 and authored by vscode-icons.

Comments

This section holds a brief description on how I experienced each day.

πŸ’” x86-32

I guess I can't blame Assembly for not being user-friendly, right? Parsing a simple list of numbers was a nightmare. Printing them, even more. And I hope nobody sees that I abused stack pointers for my loop counters. Apart from that, I am really glad that my solution fits into a 32 bit register. I wouldn't have known what to do if it didn't.

πŸ–€ Bash

I hated this. A language where x=1 is not the same as x = 1 should not exist in this world. And what special magic is $IFS after all? And when do I use single brackets, double brackets, braces or some other magic for my conditionals? Very inconsistent and ugly. Will chose Assembly over Bash next time.

πŸ–€ PowerShell

Although I hated to use -eq for simple comparisons, this looks much nicer than I initially expected. Can we please stop writing Bash scripts and use PowerShell from now on? It's also really cool that one can call .NET library functions from PowerShell.

πŸ’› PostgreSQL

Parsing a file into a table was the only challenge here. I am glad that I found this window function magic. The rest was easy. Oh, and I briefly looked into the Perl scripting mode for parsing stuff. However, I am so embarrassed by Perl that I don't even dare to commit that part.

🧑 Prolog

Just declaring the conditions to find the non-consecutive item in a list - in a mathematical way - and having Prolog figuring out how to solve that was a marvelous experience. Would code again.

🧑 Octave

While I didn't like the syntax, the standard library provided enough functions to write this in a very clean way.

🧑 R

I hated to have lists, arrays and all this inconsistent indexing magic. Plus, I know that loops are slow, but, if the language doesn't give me a nice interface to write this in a functional way, what do you expect me to do?

πŸ’œ Haskell

Very consistent and mighty once you get used to all the special characters in the syntax. However, it's a pity that you are forced to write everything in a functional way. This isn't the best way of thinking for every problem.

πŸ’œ F#

If I would just have written normal loops instead of a recursive solution, I would have written a recursive solution instead of normal loops.

πŸ’œ Scala

It feels very natural that one can write function chains from left to right. Although, I think the standard library has much less functions compared to Haskell. For one, missed itertools.groupby from Python here.

πŸ’™ Nim

This took some time to write, but it was worth it. It is fantastic to have code that is as readable as Python but compiles to fast machine code at the end of the day. Sadly, the compiler messages weren't very helpful when learning Nim and the documentation could be better. And I hate macro magic. Nevertheless, a great language.

πŸ’™ C

Parsing the input was the only real challenge here, once again. Apart from that, well, it's just C.

πŸ’™ C++

Thanks to __int128 for saving my algorithm. Plus, I learned that a % b returns different results in Python and C++. I was missing list comprehensions and tuple unpacking a lot here. And that there is no argmax() or enumerate(). And I hated that there is no .split(",") function to parse comma-separated lists easily. I probably code too much Python.

πŸ’™ Go

Good experience overall, I liked it. Go has a very well-designed standard library with plenty of utility functions. Only the syntax when appending to slices seemed a bit odd at first.

πŸ’™ Rust

The better C++, but I still don't like the syntax. All those unwrap() calls mixed with * and & characters makes the code hard to read. Moreover, I missed that I can not easily slice vectors but have to use e.g. split_last() instead.

About

Solutions for the AoC 2020, written in 25 different programming languages

License:MIT License


Languages

Language:Assembly 17.6%Language:C++ 10.2%Language:Nim 9.9%Language:C 9.3%Language:Go 6.6%Language:Haskell 6.5%Language:Dockerfile 6.2%Language:SQL 5.6%Language:F# 4.9%Language:R 4.3%Language:Prolog 3.9%Language:Rust 3.6%Language:Scala 3.2%Language:Shell 2.5%Language:PowerShell 2.3%Language:MATLAB 2.0%Language:Makefile 1.3%