Articles tagged #rust
Day 16 (Advent of Code 2022)
Let's tackle the day 16 puzzle!
Parsing
The input looks like this:
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
Valve BB has flow rate=13; tunnels lead to valves CC, AA
Valve CC has flow rate=2; tunnels lead to valves DD, BB
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
Valve EE has flow rate=3; tunnels lead to valves FF, DD
Valve FF has flow rate=0; tunnels lead to valves EE, GG
Valve GG has flow rate=0; tunnels lead to valves FF, HH
Valve HH has flow rate=22; tunnel leads to valve GG
Valve II has flow rate=0; tunnels lead to valves AA, JJ
Valve JJ has flow rate=21; tunnel leads to valve II
Day 15 (Advent of Code 2022)
The day 15 puzzle falls into the "math puzzle" territory more than "let's learn something new about Rust", but since several folks asked if I was going to continue... let's continue.
The sample input is as follows:
Sensor at x=2, y=18: closest beacon is at x=-2, y=15
Sensor at x=9, y=16: closest beacon is at x=10, y=16
Sensor at x=13, y=2: closest beacon is at x=15, y=3
Sensor at x=12, y=14: closest beacon is at x=10, y=16
Sensor at x=10, y=20: closest beacon is at x=10, y=16
Sensor at x=14, y=17: closest beacon is at x=10, y=16
Sensor at x=8, y=7: closest beacon is at x=2, y=10
Sensor at x=2, y=0: closest beacon is at x=2, y=10
Sensor at x=0, y=11: closest beacon is at x=2, y=10
Sensor at x=20, y=14: closest beacon is at x=25, y=17
Sensor at x=17, y=20: closest beacon is at x=21, y=22
Sensor at x=16, y=7: closest beacon is at x=15, y=3
Sensor at x=14, y=3: closest beacon is at x=15, y=3
Sensor at x=20, y=1: closest beacon is at x=15, y=3
Day 14 (Advent of Code 2022)
I like how the day 14 puzzle sounds, because I think it'll give me an opportunity to show off yet another way to have Rust embedded in a web page.
But first...
Let me guess: parsing?
You bet your furry ass, parsing.
Parsing
The input looks something like this:
498,4 -> 498,6 -> 496,6
503,4 -> 502,4 -> 502,9 -> 494,9
Day 13 (Advent of Code 2022)
The day 13 puzzle needs a speech therapist.
???
...because it has an awful lisp!! Ahhhahahahhhh
Are you ok? What is.. what is going on with you?
No but seriously we have what are ostensibly S-expressions, except they use JSON-adjacent notation:
[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[[1],4]
[9]
[[8,7,6]]
[[4,4],4,4]
[[4,4],4,4,4]
[7,7,7,7]
[7,7,7]
[]
[3]
[[[]]]
[[]]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[1,[2,[3,[4,[5,6,0]]]],8,9]
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:
Monkey 0:
Starting items: 79,
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...
$ cargo add nom@7
(cut)
...to parse the input into nicely-organized Rust data structures:
// 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.
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!
Go back to the homepage.