Advent Of Code is a yearly event offered by Eric Wastl: every day before Christmas, you can unlock a daily code challenge and crack it with the programming language of your choice.
It's super funny, with a pleasant Xmas/elve/reindeer... background and a soft difficulty curve (anyone with some programming experience can take the first challenges).
This year was my second participation. For the first time I was able to go through all the 25 challenges (it took me a bit more than 25 days) and the only language I used was Elixir.
I will now share with you my Advent Of code takeaways.
1 - You're not an impostor 🥸
Advent Of code is for anyone willing to improve their programming skills.
It doesn't matter if you are:
- a competitive golf programmer used to crack challenges in less than 5 minutes to rank among the first 🤯
- a student or just some folk learning programming
- a seasoned programmer willing to crank up his skills ( 👈 I'm here )
- a seasoned programmer learning a new language (I might do next season's AOC in Rust)
What relieved me the most was how welcoming and helpful the AOC community is. A new Reddit thread is opened every day and people are encouraged to share their solutions or ask for help.
2 - CS101 ... again 👨🎓
If like me you graduated computer science quite a while ago, AOC might be the perfect occasion to refresh your academic knowledge.
Advent of Code will make you think about:
- Algorithmic complexity, also known as "WTF why is my code running for 30 minutes and not yielding any result ?!?"
- Data structures. Some challenges are tough without proper data modeling. So I suggest you know the ins and outs of basic data structures (chained lists, trees, and graphs) and related algorithms (depth-first vs breadth-first tree traversal)
- Formal Grammar will help you with some challenge
- Dynamic programming also saved me an evening of hacking.
3 - Coding Kata 🥋
We are no machines and we are not required to know anything by heart: so much knowledge is reachable online, within a few seconds.
Still, knowing a few will help.
AOC helped me to muscle my memory, and I'm now able to code most challenges in a single streak without reaching the documentation or copy-pasting from previous code. During this event, I reinforced my knowledge of some of the most important Elixir APIs (
By not abusing alt-tab and staying focused in your code editor you'll be able to reach what most athletes know as flow state: this mental state in which you feel the most enjoyed and productive.
Like athletes, everyday practice will give you reflex, confidence, and improve your judgment.
4 - And a few Elixir lessons 🧪
Reddit hosts the biggest AOC community, but you can also look after smaller AOC sub-communities. I learned much from ad-hoc threads created on Elixir Forum.
Here are a few things I learned, mostly from reading at other's solutions:
- Elixir comprehensions are powerful. They let you iterate, combine, filter and reduce in few line of codes (I recommend you this article)
- Prepending is not appending - Elixir lists are not arrays. Those assumptions sound trivial but helped me make a 60 seconds program run within a few milliseconds. Elixir is immutable and as such if you want to append a single item to a list, Elixir will create a whole new copy of the list (Elixir can't modify the last item to point at your new item - immutable we said ;-). On the opposite, prepending to a list will only create a new item that will point to the previous untouched list. That's why Elixir gives us a powerful prepend operator
prepended_list = [item | list]
- Elixir most common APIs hide a few jewels that I never used in 4 years of Elixir Programming. With AOC I discovered
- You have all Erlang magic at hand. I solved some of the challenges by using raw Erlang APIs such as
digraph, or the fairly new
- Immutability brings safety. Some challenges were tricky to code in some other languages because if you didn't take care of doing deep copies of your data structure you ran into an inconsistent state. In Elixir, there is no such thing as shared mutable state, so deep copy comes for free 😎
- Immutability is slower. The cost of safety is that any write operation in Elixir will be slower than in any other languages with mutable data structures.
atomicsErlang APIs can sometimes be handy.
If you didn't know Advent Of Code before or just never tried, I hope this post will convince you to give a shot at it. AOC is not timebound and you can follow any event whenever you want at your own pace.
Oh, I forgot to mention that AOC is also a bit addictive and I may have started over from year 2015 🙊 😁 🎄