[RUBY] I enjoyed the Advent of Code, an overseas competition professional contest

This year, my colleague invited me to participate in the online competition pro event Advent of Code! It was a lot of fun and I would like to introduce it in this article.

Overview

Advent of Code (AoC) is a programming contest held by Eric Wastl (@ericwastl). Held every December since 2015, more than 150,000 athletes participated this year. image.png

Features of this contest include:

  1. One question will be asked online every day from December 1st to 25th
  1. One sample case and one test case are given for each part
  1. The difficulty of the problem is relatively easy
  1. Scores will be given to those who answer correctly early
  1. There are two types of rankings: global rankings and private rankings.

How to enjoy

Did you get a feel for what AoC looks like? In this chapter, I will summarize the points that I actually enjoyed participating in.

The fun of having a two-part problem

All AoC questions are divided into two parts. For example, what was considered in 2D space in Part 1 was expanded to 3D in Part 2.

If you solve Part 1, you will be able to read the problem of Part 2, but at this time the problem may change in an unexpected direction.

In AoC, I basically want to solve quickly, so I want to reuse the implementation of Part 1 as much as possible, but if the implementation of Part 1 is not good, I will be forced to rewrite everything in Part 2. For this reason, it is necessary to anticipate the deployment of 2 as of Part 1 and consider reusability, but implement it well with simplicity that does not cause much time loss if the prediction is wrong. I personally enjoyed this sense of balance.

Check out the Reddit community r/advent of code

Many AoC athletes use this Subreddit as a place to interact. Here, each answer code is shared and discussions about the problem are held every day during the period of AoC.

Also, there are many people who focus on visualizing the solution, and if you solve it yourself and then browse it with Visualization flare, you will enjoy it twice.

Comical setting issues

The problem is basically made up of the theme that Santa Claus prepares for Christmas.

As is often the case with AtCoder, the problem setting is chaotic and it's fun just to imagine the scene. For example, 7th day of 2020 is a problem of recursive bags with several bags in the bag, and posted material image that imitated it was exciting. It was.

image.png

I'm glad I participated

With the above fun, I was able to finish the race for 25 days safely. Now, let me summarize some of the things I got from completing the race.

Learn how to code concisely

Since quick solving is important in AoC, it is desirable to write the code short and concise. This is a general-purpose skill that does not depend on a specific algorithm, so you can grow during AoC.

For example, if you want to take the product of each element in an array, you can simplify it as follows.

Example of writing.rb


arr = [1, 1, 4, 5, 1, 4, 1, 9, 1, 9]

#Stupid writing example
mul = 1
arr.each do |a|
    mul *= a
end

#Concise writing example
mul = arr.inject(&:*)

Once I solved the problem, I read the code of others posted on Reddit looking for a better way to write it. Depending on the item, the knowledge I gained that day could be put to good use immediately the next day, so it was easy to get a sense of growth.

Forced to "think" "time once a day

When I work, I think that there may be fewer opportunities to think mathematically and computer science. At AoC, only one question is provided each day, and the difficulty level is moderate. I think that many people (and myself) are not good at stacking up steadily, but with AoC, you can naturally realize an approach of only one hour a day.

Rankings also improve motivation because of the desire to maintain the rankings and the impatience that other people are well aware of them.

This makes it easy to get into the habit of thinking and writing code.

Become a story of talking with colleagues and friends

Since everyone solves the same problem every day, it is easy for participants to talk to each other. In that sense, it's an entertainment similar to drama and anime!

At the end

I introduced an event called AoC. If you are interested, why not check the problems so far and get a feel for the atmosphere?

Problems can be solved at any time, and 2020 problems can be accessed here. You can also refer to here for problems before last year.

The next event will be held one year later (2021/12), so please join us!

[^ 1]: Stars are like medals, so there is no point in collecting them. [^ 2]: Proposals to change this specification have been made many times, but it seems that there are no plans to change it at the moment due to server load problems

Recommended Posts

I enjoyed the Advent of Code, an overseas competition professional contest
I made the server side of an online card game ①
I read the source of ArrayList I read
I read the source of Integer
I read the source of Long
I read the source of Short
I read the source of Byte
I read the source of String