Saving Christmas with Kotlin
It’s been a month since I’ve saved a Christmas. Now, I feel it’s time to tell you exactly how I did it. I wasn’t alone, though. My faithful companion was crucial to the success of my mission. Yes, Kotlin, I’m talking about you.
But let’s return to the day when it all started:
I was minding my own business on a ship at sea when the overboard alarm goes off! I rushed to see if I could help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!
Before I knew it, I was inside a submarine the Elves kept ready for situations like this. It was covered in Christmas lights (because of course it is), and it even had an experimental antenna that should be able to track the keys if I could boost its signal strength high enough; there was a little meter that indicated the antenna’s signal strength by displaying 0–50 stars.
My instincts told me that in order to save Christmas, I needed to get all fifty stars by December 25th.
It turns out that 200K+ other people happened to get into a similar situation. You can still see the complete log of our adventures on this site. Some people call it the “Advent of Code” and say it happens yearly.
My way down
It took me 25 days and 50 challenges (yeah, two challenges per day) to get those sleigh keys and save the Christmas. Every day at 7 a.m. (UTC+2), we reached a new milestone that unlocked two more challenges to solve.
Most of them took from one to two hours to get done. Thank God there was a pretty good Internet connection in my submarine (I could even work remotely and didn’t need to take a vacation for such a noble task), so I still had plenty of time to share my ideas and solutions:
- Ideas and Solutions for Advent of Code 2021 in Kotlin — Part 1/4
- Ideas and Solutions for Advent of Code 2021 in Kotlin — Part 2/4
- Ideas and Solutions for Advent of Code 2021 in Kotlin — Part 3/4
- Ideas and Solutions for Advent of Code 2021 in Kotlin — Part 4/4
Spending 25 days locked in a submarine and solving challenges isn’t necessarily the funniest thing to do unless you do it with Kotlin ❤️
The Kotlin way
Kotlin appeared ten years ago as a better alternative to Java and since then gained many fans among developers (mostly Android devs, but also backend, frontend, data science, and so on). I use this language daily for work and fun as a mobile developer myself.
Surprisingly, Kotlin has a good potential for competitive programming thanks to its full two-way compatibility with Java and modern functional syntax. So it was a no-brainer for me to choose Kotlin as my companion on this adventure.
Now, with all the challenges solved and Christmas saved, I can summarize the pros and cons of my choice:
- Any challenge starts with a data input, which varies a lot. Even though Kotlin’s I/O implementation isn’t the most efficient on the market, it was more than enough for a single-test nature of “Advent of Code” tasks.
- Once the raw data is entered, we need to parse and transform it to use in our solutions. This is where Kotlin shines — arguably the most elaborate collection of methods and tools for this purpose.
- This year’s “Advent of Code” included challenges that required knowledge and execution of some advanced programming concepts and technics like dynamic programming, recursion, graph theory, NP-complete heuristics, and just complex implementation tasks. Not a single time I was limited by Kotlin’s capabilities or available data structures — everything is in place. And even more, the standard library of extensions unlocked utterly new ways of crafting exquisite solutions to somewhat typical problems.
- The language itself is worth very little without developer tools that are needed to write, debug, compile, and execute the code in the given language. I’m used to Android Studio as a mobile developer, which isn’t the best choice for simple programming tasks. But IntelliJ IDEA provides a similar experience with Kotlin and is excellent for any task, small or big.
- And last, but not least — efficiency. Having a correct solution that needs a few millennia to execute isn’t great. Especially, if it’s related to the language of your choice. Even though Kotlin is slower than C++, it never stopped me from getting an answer in an acceptable time.
So the overall experience was a success for me. It was the first time I got all 50 stars 🌟 And I’ve learned many new things in Kotlin as well.
Christmas saved, now what?
Well, what do heroes do after they save the world? I’ll spend more time with my old friend Kotlin. Maybe we will solve more competitive programming tasks together. Perhaps we will try to write some backend or even frontend.
I don’t even mention mobile apps, which we develop teamwise for quite a long together. Did you know Kotlin can do some work (or maybe even all the work shortly) for both, Android and iOS? Yes, he is that cool!