Skip to content

🎄 My solutions for the JetBrains 'Advent of Code' puzzles in 2021-2022 using Kotlin.

Notifications You must be signed in to change notification settings

ISchwarz23/advent-of-code

Repository files navigation

Advent of Code

                            |                         _...._
                         \  _  /                    .::o:::::.
                          (\o/)                    .:::'''':o:.
                      ---  / \  ---                :o:_    _:::
                           >*<                     `:}_>()<_{:'
                          >0<@<                 @    `'//\\'`    @
                         >>>@<<*              @ #     //  \\     # @
                        >@>*<0<<<           __#_#____/'____'\____#_#__
                       >*>>@<<<@<<         [__________________________]
                      >@>>0<<<*<<@<         |=_- .-/\ /\ /\ /\--. =_-|
                     >*>>0<<@<<<@<<<        |-_= | \ \\ \\ \\ \ |-_=-|
                    >@>>*<<@<>*<<0<*<       |_=-=| / // // // / |_=-_|
      \*/          >0>>*<<@<>0><<*<@<<      |=_- |`-'`-'`-'`-'  |=_=-|
  ___\\U//___     >*>>@><0<<*>>@><*<0<<     | =_-| o          o |_==_|
  |\\ | | \\|    >@>>0<*<<0>>@<<0<<<*<@<    |=_- | !     (    ! |=-_=|
  | \\| | _(UU)_ >((*))_>0><*<0><@<<<0<*<  _|-,-=| !    ).    ! |-_-=|_
  |\ \| || / //||.*.*.*.|>>@<<*<<@>><0<<@>>>>>|  ( ~~~ )/   (((((((())))))))
      ~~~~~~~~         '""""`------'  `w---w`     `------------'

In this repository, I'm about to provide solutions for the Advent of Code1 puzzles using Kotlin language.

Motivation

I decided to do the Advent of Code in Kotlin, as it is my favorite programming language which I use way too infrequently. I'm only able to use them in my side projects and unfortunately not in my professional career at my current employer.
I use this event to get a broader knowledge about the Kotlin standard library.

Repo Structure

For each day/puzzle there is a separate file inside the source folder with the pattern DayXX (e.g. Day01). This file contains all the code that was used to solve the puzzle.
The correctness is checked using a JUnit 5 tests. There is one test file for each day using the name pattern DayXXTest (e.g. Day01Test). These tests use the sample input from the puzzle explanation to check if the code is correct. Thereafter, the code is called with the real puzzle input.
This input data is stored in text files in the "input" folder on the project root. The file name pattern of the input files is dayXX.txt (e.g. day01.txt). The mentioned sample data is stored in files with the name pattern dayXX_example.txt ( e.g. day01_example.txt).

Usage

The described files described in the section "Repo Structure" can be generated for a specific day using the command make new_day. This will generate the files required for the current day of the month and the current year. This behavior can be overridden using make new_day DAY=<day> YEAR=<year> (e.g. make new_day DAY=1 YEAR=2019).

Setup

To download the actual puzzle input when executing the make new_day ... command (only possible when the puzzle for the requested day was already released) and be able to automatically upload your puzzle answers, you need to store your session cookie to the file session.txt in the project root. The file content should look like session=abc...xyz.

Log of my AoC Journey 2022

I tried to log my results and thoughts for each puzzle after solving it.

# Name Stars Comment
1 Calorie Counting ⭐⭐ Was not able to find a way to calculate the calorie sum as stream, so I did it in a loop.
2 Rock Paper Scissors ⭐⭐ Guess there is a more performant way, but I focused more on readability.
3 Rucksack Reorganization ⭐⭐ In my opinion this was the most easy puzzle so far.
4 Camp Cleanup ⭐⭐ Also a pretty easy one, when sorting the pair of section assignments.
5 Supply Stacks ⭐⭐ Today, parsing the input was more difficult than the actual puzzle.
6 Tuning Trouble ⭐⭐ Pretty short puzzle today. Took me less than 10 minutes for both parts.
7 No Space Left On Device ⭐⭐ Today I was not able to work on the puzzle when it was released. Had to postpone it, until I finished working.
8 Treetop Tree House ⭐⭐ Found a pretty generic solution to 'iterate' over the trees. Don't know it is easy to understand.
9 Rope Bridge ⭐⭐ Unfortunately I had to spend a long time debugging, as I had a bug when moving diagonal.
10 Cathode-Ray Tube ⭐⭐ Very sub-optimal circumstances today. First I started more than half an hour late, then it took me ages to understand the second part.
11 Monkey in the Middle ⭐⭐ A lot of parsing today. But puzzle itself was not that hard.
12 Hill Climbing Algorithm ⭐⭐ Lost a lot of time, as my algorithm never find a solution. I expected my algorithm to be buggy, instead I had the wrong assumption, that is is only allowed to move one height level down. But there was no limit described in the puzzle.
13 Distress Signal ⭐⭐
14 Regolith Reservoir ⭐⭐
15 Beacon Exclusion Zone ⭐⭐ Pretty easy compared to the ones before.
16 Proboscidea Volcanium ⭐⭐ Solutions takes 5 minutes to finish for part 2. Good enough for now...
17 Pyroclastic Flow ⭐⭐ This one was really fun! :)
18 Boiling Boulders ⭐⭐
19 Not Enough Minerals ⭐⭐
20 Grove Positioning System ⭐⭐
21 Monkey Math ⭐⭐ Really liked this one! 'Cause Maths ;)
22 Monkey Map ⭐⭐ Cool puzzle, but I was not able to implement a general solution for part 2. So for now I use hardcoded rules only working for the given input.
23 Unstable Diffusion ⭐⭐ Pretty easy one
24 Blizzard Basin ⭐⭐ Solved using A*
25 Full of Hot Air ⭐⭐

Log of my AoC Journey 2021

I tried to log my results and thoughts for each puzzle after solving it.

# Name Stars Comment
1 Sonar Sweep ⭐⭐ Did a very basic/unimproved implementation that did the job. No performance improvements needed to calculate solutions.
Edit: Did improvement using windowed() function.
2 Dive! ⭐⭐ Did not see the challenge in this puzzle. Straight forward implementation did the job.
3 Binary Diagnostic ⭐⭐ Can't really estimate the quality of the solution, but it looks a bit bloated. Guess there is a more elegant way to solve this puzzle.
4 Giant Squid ⭐⭐ Implemented an object-oriented solution. Instead of a 2d-array I used a simple list for the board.
5 Hydrothermal Venture ⭐⭐ Implemented an object-oriented solution again. Already guessed the part 2 of the puzzle, so diagonals were supported right from the beginning.
6 Lanternfish ⭐⭐ Part 1 was straight forward (5 min). Performance was so bad that I had to completely redo it for part 2. But now I'm pretty proud on the solution, as it is simple and fast.
7 The Treachery of Whales ⭐⭐ Was pretty fast in finding solution for part 1 (5 min). Also for part 2 (10 min), but had issues as the best position isn't always exactly the average of the positions.
8 Seven Segment Search ⭐⭐ Can't make any statement about the puzzles level of difficulty, as I had only 3 hours of sleep last night.
9 Smoke Basin ⭐⭐ Added some foolish bugs to the recursion of part 2. This required some time to correct it. Best would have been to start part 2 all over instead of bug fixing it.
10 Syntax Scoring ⭐⭐ Really liked this puzzle. As soon as you see, that the issue is related to stacks, it is a straight forward implementation.
11 Dumbo Octopus ⭐⭐ Tried to implement a highly optimized solution from the beginning, but failed. Started all over again and implemented it just as described in the puzzle. Solution was fast enough.
12 Passage Pathing ⭐⭐ As I did a route optimization side project (using A* algorithm) this was straight forward. Instead of finding only the optimal route (as in my side project), I just needed to find all routes (which is more easy).
13 Transparent Origami ⭐⭐ Had some issues cause I was mixing up horizontal and vertical folding all the time. So had to invest some time in bug fixing.
14 Extended Polymerization ⭐⭐ Needed to reimplement everything for part 2, as part 1 was very in-performant. This took me a looot of time.
15 Chiton ⭐⭐ Only needed to do simple adaptations on solution of part 1 to be able to process part 2 in time. But I did a dumb error when calculation neighbours of current field which cost me about 2 hours to find.
16 Packet Decoder ⭐⭐ Really liked the topic this puzzle. Also the implementation went pretty smooth.I had only some minor bugs that were found during testing using the given samples.
17 Trick Shot ⭐⭐ This puzzle took me a long time, as I tried to implement it iteratively. When doing the maths using pen and paper it was solved pretty fast. Especially part 1 is bad code but great maths.
18 Snailfish ⭐⭐ I'm not quite happy with my solution, as the code is not very easy to understand. Maybe even the way I implemented the recursion can be improved.
19 Beacon Scanner ⭐⭐ I guess my solution is the brute force way. It takes about 20 seconds to solve one of the parts. There has to be a better/more elegant way, but I was not able to find it.
20 Trench Map ⭐⭐ This puzzle was more easy compared to the previous ones. Only applying the filter to the infinite surrounding pixels was a bit tricky.
21 Dirac Dice ⭐⭐ Part 1 was too easy, so expected part 2 to be very hard and I was right. Nevertheless I guess my solution was very good, as it finds the correct solution in about 500ms.
22 Reactor Reboot ⭐⭐ I created an improved version for part 2, but it was not fast enough. I would need to invest more time to find a better solution for part 2. Edit: The improvement for part 2 was pretty simple. I just adapted the splitting logic of the clusters, to produce the least number of sub-clusters.
23 Amphipod ⭐⭐ Solution is working for part 1, but is too slow for part 2. Unfortunately, I have no idea how to improve it. Edit: The improvement for part 2 was pretty simple. I just had to reduce the size of the known locations by storing the hash of it instead of the complete objects.
24 Arithmetic Logic Unit ⭐⭐ Was finally able to solve the puzzle after over 1 year with a lot of help from the internet.
25 Sea Cucumber ⭐⭐ Implemented a very nice solution for part 1 which is not only fast, but also adaptable. The order of the movement can be specified. Unfortunately I don't have enough stars to attempt part 2, so I have to come back to it later.

Footnotes

  1. Advent of Code – an annual event in December since 2015. Every year since then, with the first day of December, a programming puzzles contest is published every day for twenty-four days. A set of Christmas-oriented challenges provide any input you have to use to answer using the language of your choice.