Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Very Concise AoC solutions - 2020 in Rust, 2021 in Julia, 2022 in Kotlin, 2023 and 2024 in Python

License

NotificationsYou must be signed in to change notification settings

LiquidFun/adventofcode

Repository files navigation

2024 - 50 ⭐ - Python

2023 - 50 ⭐ - Python

2022 - 50 ⭐ - Kotlin

2021 - 50 ⭐ - Julia

2020 - 50 ⭐ - Rust

2019 - 10 ⭐ - OCaml

The above tiles are clickable, leading to the solution of the corresponding day.


The graphic above has been created usingaoc_tiles. Feel free to use it, it's easy to set up!


My solutions:

  • are self-contained and use no util files and mostly no libraries.
  • are written in a very concise and functional style (only 5/100 solutions have >=70 loc as calculated bycloc)
  • try to be (too) clever, this is not code written for readability, but for pushing language expressibility.
  • solve both parts of each problem at once. I believe structuring the code so that it solves both parts is often an interesting challenge.
  • expect input viastdin and output (generally) 2 lines tostdout with the answer to part 1 and part 2.
  • (generally) parse input as it is given without modifying or pasting it into the code as an array. Parsing the strings in as little code as possible is a huge part of AoC.

and are written in a different programming language each year:

  • 2023: Initially I wanted to use Rust for this year, but instead I focused on getting on the leaderboard withPython (successfully on day 18 and 25!). In the last days I even started using libraries (Z3/networkx). Python is my strongest language, so no surprises there. I did 5 days in Rust as well, but found it too frustrating and had too little time for 2 solutions per day.
  • 2022: UsingKotlin for the first time. Playing with streams a lot, many days are completed by only using streams. The first 15 days havePython solutions as well in order to be able to submit quicker and get better times on the leaderboard.
  • 2021: UsingJulia for the first time. Because it supports numpy-like element-wise operations natively this was a great choice for AoC. If I used more Julia it would likely be my go to language for AoC right now.
  • 2020: UsingRust for the first time. Solved 8 days initially. Revisited in 2024 and solved all of them. This time I liked Rust much more. I ended up writing very concise and functional Rust. After getting used to it it was quite fun. All rust solutions are below 100 loc (as calculated bycloc).

Not part of the repository yet, since these are incomplete and the code is not good (might revisit them later):

  • 2019: First time participating, solved 5 days withPython. Trying OCaml in 2024.

Running

  • 2023:python 01.py < input.in with Python 3.12
  • 2022:kotlinc 01.kt -include-runtime -d 01.jar && kotlin 01.jar < example.in (or use intellij, kotlinc is very slow via CLI, 5+ seconds to compile)
  • 2021:julia 1.jl < input.in
  • 2020:cargo run --release --bin 01 < input.in or with autoresolve current dir, auto-refresh and time-taken:cargo watch -s 'time cargo run --release --bin '$(basename $PWD)' < '$(basename $PWD)'/input.in' with Rust version 1.80.1
  • 2019:ocaml 01.ml < input.in with OCaml 5.2.0

In order to test the programs you can pipe the input to the program, for example:julia 1.jl < input.in. The correct output is saved in theinput.ans. Instead of doing this manually, I use myprogram-tester.sh script (seehere), which runs the given program on all*.in files in the directory, and tests whether the corresponding*.ans file matches the given output. I have mapped that program onEnter in vim, which makes testing programs easy.

Programs are initialized with theinit-day.sh script. I.e. typinginit-day.sh 10 initializes the 10th day by creating a folder named10 and downloading the input test case with thesession.cookie.

My favorite solution2023/18

Releases

No releases published

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp