Articles tagged #rust

Day 12 (Advent of Code 2022)

Alright! The day 12 puzzle involves path finding, and it seems like a good time to lean more heavily on the WASM embeds I've set up for the previous parts.

Let's start by setting up the types we'll want!

Types and parsing

Our input is a heightmap, like so:

Sabqponm
abcryxxl
accszExk
acctuvwj
abdefghi

Where 'a'..='z' is a square with a given elevation (from lowest to highest), is the start, and is the end.

Day 11 (Advent of Code 2022)

It's a new day, it's a new advent of code puzzle.

In that one, we have to apparently cosplay as an IBM mainframe and just.. crunch them numbers. This doesn't look fun, and I can't think of a clever twist to make it fun, so let's try to make it short and sweet.

Parsing

Our input looks like this:

Rust code
Monkey 0:
  Starting items  
  Operation new = old  
  Test divisible by 
    If true throw to monkey 
    If false throw to monkey 

Monkey 
  Starting items    
  Operation new = old + 
  Test divisible by 
    If true throw to monkey 
    If false throw to monkey 

etc
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.

Go back to the homepage.