Articles tagged #advent-of-code

Day 10 (Advent of Code 2022)

Onwards! To the day 10 puzzle.

I don't see a way to make part 1 especially fun — so let's just get to it.

Parsing

As usual, let's reach for the nom crate...

Shell session
$ cargo add nom@7
(cut)

...to parse the input into nicely-organized Rust data structures:

Rust code
// in `src/main.rs`

use nom::{
    branch::alt,
    bytes::complete::tag
    combinatormap value
    sequencepreceded
    IResult



  
    Noop
    Addx


  
       ->   
         noop = 
         addx =  nomcharactercompletei32
        Noop noop addx Addxi
    

      ->  
          
            Noop => 
            Addx_ => 
        
    

Day 9 (Advent of Code 2022)

The Advent of Code is not a sprint: it's a marathon: sometimes you've got to stop and smell the roses.

Bear

I... what? That's not.. have you done a marathon before?

No, and I haven't taken any creative writing classes either, I think you can tell. Anyway: Day 8 was a bit aggravating for me. In 2020 I gave up AoC after Day 14 I think, and then I skipped a year. It doesn't help that it overlaps some holidays and stuff, but!

Day 8 (Advent of Code 2022)

In the day 8 problem, our input is a height map:

30373
25512
65332
33549
35390

This is a 5x5 grid, and every number denotes the height of a tree. For part 1, we must find out how many trees are visible from the outside of the grid.

If we consider the first row, from the left: only the 3 is visible: it obscures the 0. From the right, 3 and 7 are visible.

Day 7 (Advent of Code 2022)

The day 7 challenge talks about trees! File trees that is.

The temptation to solve it before starting to write this article so I don't look silly is high, but I'm explicitly not doing so, so that we can bang our collective heads against any walls at the same time, and see how we can get out of it! Trees are serious business!

Part 1

The sample input looks like this:

Day 6 (Advent of Code 2022)

Today I am joining you from the relative discomfort of my living room (since my better half has commandeered the home office due to Way Too Many Calls) to tackle the day 6 challenge, which I'm excited about: maybe despite, maybe because of, the low-grade fever I'm under.

Part 1

Our input is a jumble of letters, and we're supposed to find the position of the first substring that's "four different characters".

Day 5 (Advent of Code 2022)

Part 1

The day 5 challenge actually looks fun!

Our input looks like this:

    [D]
[N] [C]
[Z] [M] [P]
 1   2   3

move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2

Which is a visual representation of stacks, and so, for once, we have some serious parsing to do, and that means I finally have a good reason to bust out the nom crate.

Day 4 (Advent of Code 2022)

Part 1

Let's tackle the day 4 challenge!

In this one, we get an input like this:

2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8

Each line has two ranges: the first line has ranges containing 2, 3, 4, and 6, 7, 8. We must count how many pairs have ranges where one fully contains the other.

In Rust, we can express this with "inclusive ranges" (), and those implement , so we can do:

Day 3 (Advent of Code 2022)

Part 1

I'm not sure where the day 3 challenge is going, because the problem statement for the first part is kinda convoluted.

As usual we have an input, like this:

vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw

Each line represents the contents of a "rucksack", divided in two halves (which are called "compartments"), so for line 1:

Go back to the homepage.