| _...._
\ _ / .::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.
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.
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
).
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
).
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
.
I tried to log my results and thoughts for each puzzle after solving it.
# | Name | Stars | Comment |
---|---|---|---|
1 | Historian Hysteria | ββ | Straight forward. |
2 | Red-Nosed Reports | ββ | Not happy with the code for part 2. |
3 | Mull It Over | ββ | Straight forward. |
4 | Ceres Search | ββ | Straight forward. |
5 | Print Queue | ββ | Straight forward. |
6 | Guard Gallivant | ββ | Not happy with my part 2 solution. |
7 | Bridge Repair | ββ | Straight forward. |
8 | Resonant Collinearity | ββ | Straight forward. |
9 | Disk Fragmenter | ββ | Didn't think about more than 1 digit numbers. This is why I had to reimplement my solution. |
10 | Hoof It | ββ | Straight forward. Part 2 was even more easy than part 1. |
11 | Plutonian Pebbles | ββ | Pretty easy when using a map (instead of a list). |
12 | Garden Groups | ββ | It took me a while to calculate "sides" of the gardens. |
13 | Claw Contraption | ββ | It took me very long to realize the problem is a linear system of equations. |
14 | Restroom Redoubt | ββ | Really liked the style of part 2. |
15 | Warehouse Woes | ββ | Had to reimplement everything for part 2. |
16 | Reindeer Maze | ββ | Improved to much in the beginning. Part 2 forced me to remove most of the performance improvements. |
17 | Chronospatial Computer | ββ | Part 1 was very simple, but it took me a while to find a solution for part 2. |
18 | RAM Run | ββ | Worked unexpectedly smooth. Took less than 50min. |
19 | Linen Layout | ββ | Worked unexpectedly smooth. Took less then 1h. |
20 | Race Condition | ββ | First I misunderstood the problem completely. Then my first working solution for part 1 took 2.5h. Finally solved both parts. Unfortunately, solution takes nearly 30 seconds for part 2. |
21 | Keypad Conundrum | ββ | Took me a while to find a scalable solution. The final solution uses recursion and a cache and takes only about 250ms to solve part 2. |
22 | Monkey Market | ββ | Pretty easy compared with the once from yesterday and the day before yesterday. But my solution takes more than 15s to complete part 2. |
23 | LAN Party | ββ | Improved part 1 by directly starting network at pcs starting with 't'. This improvement made my part 2 not finding any solution. Took me a while to realize this. |
24 | Crossed Wires | ββ | Part 2 really made me crazy. Tried identifying possible wrong outputs and permuted them which would have calculated for years to find a solution. In the end I just defined how a "add logic structure" should look like and checked where the input for the puzzle was different. |
25 | Code Chronicle | ββ | Like every year, the last puzzle was very easy. |
I tried to log my results and thoughts for each puzzle after solving it.
# | Name | Stars | Comment |
---|---|---|---|
1 | Trebuchet?! | ββ | |
2 | Cube Conundrum | ββ | |
3 | Gear Ratios | ββ | |
4 | Scratchcards | ββ | |
5 | If You Give A Seed A Fertilizer | ββ | |
6 | Wait For It | ββ | |
7 | Camel Cards | ββ | |
8 | Haunted Wasteland | ββ | Had to look up how to calculate the lcm, but besides that pretty easy. |
9 | Mirage Maintenance | ββ | Very easy one. |
10 | Pipe Maze | ββ | Part 2 challenged me, until I realized how to identify how a point is inside or outside a polygon. |
11 | Cosmic Expansion | ββ | Liked this puzzle a lot! |
... | |||
15 | Lens Library | ββ |
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 | ββ |
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
-
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. β©