.NET Nakama

Improving your .NET skills

A Developer's Adventures of Code

January 18, 2021 (~7 Minute Read)
ADVENT OF CODE PUZZLES PROGRAMMING SKILLS CODE KATA

Introduction

The Advent of Code (AoC) is a calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language. Programming puzzles are commonly used in job interviews, in university courses, and to practice and improve programming skills. Solving programming puzzles (exercises) repeatedly, it’s known as code kata (from the Japanese concept of kata in the martial arts). Learning can be fun, for example solving programming puzzles with friends or challenge each other.

Some of my colleagues and I decided to solve the AoC puzzles and challenge each other mainly for fun and learning and then for a prize for the first three places. The challenge was to solve 25 programming puzzles (separated in two parts) which were announced at midnight EST/UTC-5 in the aforementioned website on a daily basis (from 1 to 25 of December). To solve a puzzle, you would have to read the instructions carefully, implement your solution and run it on a provided dataset to calculate an output result. If the result of each part of the puzzle is correct, you will earn a Star (total of 50 Stars), and points based on the time you spend to solve the puzzle since the announced time. In our case, the challenge was just to solve the puzzles and not a speed contest (taking account only the stars).

Our daily tickets as a developer are similar to puzzles, which we solve on a daily basis to complete a task. In this article, regardless of the challenge results, I will describe my experiences in AoC and what we can learn from such a challenge in compassion to our daily tasks and tickets.

Puzzle Description VS Developer Tickets

The majority of the AoC puzzles descriptions were very informative, describing a story-adventure of a developer (background) and the final goal with examples. This was a great reminder of how a developer’s ticket should be organized to be effective. For example, a ticket should among others to:

  • Describe a user story, to understand the user’s need at a high level. This will help the developer to understand why this ticket is important, how it would help the user, and which solution is appropriate.
  • Clearly define its goals and scope, to fully understand what should be implemented and what it should affect (brand, site, region, etc.). Clear examples are always welcomed. A confusing goal or example may result in spending several hours to understand it. The example in AoC 2020 puzzle 17 is such a case, in which a lot of people were confused.
  • Have an up-to-date list of acceptance criteria, which describes the requirements that must be met in order to mark the ticket as completed.
After trying to make sense of the AoC 2020 puzzle 17 example for one hour or more.
Figure 1. - After trying to make sense of the AoC 2020 puzzle 17 example for one hour or more (Source).

Puzzle Solution Time

Solving puzzles regularly (e.g. AoC, code katas) will increase our efficiency and decrease the required time to solve them. This is the same in a working environment, in which we are solving the problems (tasks) of our tickets and we are getting better at the same time. For that purpose, we could dedicate some time to think or search on the Internet for a different solution (way of thinking, existing libraries, tools, etc.), see other people’s code, discuss it with our colleagues, etc.

The time to solve a problem is highly related to the first selected solution and not how quick you start typing (think first). To quickly select one of the best possible solutions, it needs experience gained from solving related problems and many failed attempts. This is where puzzles, katas and hobby-projects can help. We cannot all be super-fast, as shown in the next meme below, but we can keep improving ourselves.

Instantly thought of this when I saw this template from r/adventofcode

Stuck in a Puzzle or Ticket

Day 20 of the AoC 2020 has come, the weather was good and Part 1 was solved, then part 2 was… nope! and some people decided to decorate their Christmas tree and others just quit trying. Maybe day-20 puzzle was not that hard in the end, but if you stuck in a not so good idea, you are stuck.

Maybe decorating the tree is a better choice.
Figure 2. - Maybe decorating the tree is a better choice (Source).

You may be the best developer ever existed, but still, sometimes you will have to ask for help to solve a puzzle or complete a ticket at work. Maybe you could achieve it without asking and spend several hours or days, but at the end of the day, is this efficient (especially in a work environment)?

We could dedicate some time to work on the specific problem in order to have a good understanding of it, and then if we stuck, we will be able to make the right questions or search for a solution in the right direction in order to solve the problem. We have to accept that we cannot know everything!

Be humble and share your knowledge, communicate with your colleagues to provide help when needed and use their experience to improve yourself (don’t be afraid to ask). In addition, do not be afraid to check a different way of thinking or restart from scratch (depending on the context), sometimes a different perspective may help “clean” your head.

Restart from scratch, sometimes may help 'clean' your head.
Figure 3. - Restart from scratch, sometimes may help "clean" your head. (Source).

Efficient Solutions

In some AoC puzzles, the second part was focused on “load testing” our implementation (of the first part). For that reason, our implementation should be optimized enough to solve the puzzle in a relatively short time.

Just wait patiently for the results (a star is a star) :P
Figure 4. - Just wait patiently for the results (a star is a star) 😛 (Source).

This kind of quiz is very helpful to understand how our code will operate under heavy load (e.g. from a marketing offer). In addition, it shows the importance of load testing (e.g. for our APIs) to understand its boundaries and find bugs (e.g. from memory leaks, race conditions, etc.).

Summary

The Advent of Code (AoC) it’s a programming challenge of 25 small programming puzzles (divided into two parts), which were announced in a daily basis (at midnight EST/UTC-5). Some of my colleagues and I decided to accept the Advent of Code and challenge each other, mainly for fun and learning. This was my first time participating in AoC and I can say that I missed it when it was over. In addition, I really enjoyed the posted funny memes. The AoC provides programming puzzle events since 2015 so, there are more programming puzzles available 😉.

It was a challenging and satisfying puzzle-solving, which I recommend to give it a try. There were puzzles that required more effort (at least for me) and depending on your daily schedule it may be exhausting, but you can always solve them in your time.

The morning after the end of AoC.
Figure 5. - The morning after the end of AoC (Source).

Solving programming puzzles can be used for honing your programming skills, but we can learn much more because our daily tickets as a developer are puzzles too. Thus, we can see (or remember) the importance of:

  • A well-described ticket (not confusing), with clear goals and scope, with an up-to-date list of acceptance criteria.
  • Dedicating some time to think or search on the Internet for a different solution (way of thinking, existing libraries, tools, etc.), see other people’s code, discuss it with our colleagues, etc.
  • Being humble and sharing knowledge. To communicate with colleagues to provide help when needed and use their experience (by making questions) to improve ourselves.
  • Load testing our implementations to understand its boundaries, find bugs (e.g. from memory leaks, race conditions, etc.) and finally make it more efficient.

How was AoC challenge for you? Would you give it a try?

If you liked this article (or not), do not hesitate to leave comments, questions, suggestions, complaints, or just say Hi in the section below. Don't be a stranger 😉!

Dont't forget to follow my feed and be a .NET Nakama. Have a nice day 😁.