Back to overview

Advent of Code

Reading time approx. 2 minutes
19.12.2023

We are taking part in Advent of Code this year for the second year running - the playful programming challenge that happens annually over the Christmas period. Launched in 2015 by Eric Wastl, the online puzzle has since enjoyed great popularity in the developer community.

From 1 to 25 December, two programming tasks are published on the website every day. These can be solved by participants in a variety of programming languages to earn points. All participants automatically take part in the global leaderboard - the overall ranking list. It is not only the number of puzzles solved that counts, but also speed. Advent of Code also offers the option of creating a private leaderboard. This is a separate ranking list that is created by one person and is only visible to members of the leaderboard. This mode is particularly suitable for competing against each other within the company.

There are only a few days left until 25 December, and first place on our leaderboard is very much stiff up for grabs. For many of our employees, the playful idea of familiarising themselves with a new programming language is more important than the competition itself - for which there is also a small prize from our management. One of our employees solved the second day's task using the Rust programming language. The first part of the task was to find out which of the games are actually possible.

Solution:

```clike
pub fn solve(input: &str) -> Result<String, String> {
    let games = parse_games(input);

    let possible_games: Vec<&Game> = games
        .iter()
        .filter(|&game| {
            game.rounds.iter().all(|round| {
                round.cube_draws.iter().all(|draw| match draw.color {
                    Color::Red => draw.cube_count <= RED_CUBES,
                    Color::Green => draw.cube_count <= GREEN_CUBES,
                    Color::Blue => draw.cube_count <= BLUE_CUBES,
                })
            })
        })
        .collect();

    let game_id_sum: u32 = possible_games.iter().map(|&game| game.id as u32).sum();
    Ok(game_id_sum.to_string())
}

Filters are used to ensure that only those that fulfil the conditions remain.

Advent of Code offers a good opportunity to try things out and expand your own skillset. The competition is also a good starting point for people with only rudimentary programming experience. Incidentally, it is also worth taking a look at the linked websites of the various sponsors. These range from small easter eggs with achievements to pages in Klingon.