Articles tagged #rust
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:
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:
Part 1
In the day 2 challenge, we're playing Rock Papers Scissors.
We're given a strategy guide like so:
A Y B X C Z
Left column is "their move": A means Rock, B means Paper, C means Scissors. Right column is "our move": X means Rock, Y means Paper, Z means Scissors.
Each line corresponds to a turn, and we must calculate the total score we get. Picking "Rock" gives 1 point, "Paper" gives 2 points, and "Scissors" gives 3. Losing the round gives 0 points, drawing gives 3, winning it gives 6.
Two years ago, I did part of Advent of Code 2020 using the Rust language. It was a lot of fun, so let's try it again!
The problem statement
Our input looks something like this:
1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
Each group of lines separated by an empty line is a list of food items an elf is carrying: each line corresponds to the number of calories in that food.
Let's use the Advent of Code 2022, a series of programming challenges of increasing difficulty, to learn more about the Rust programming language.
async_trait
's one weird type ascription trick
Now that I got the Log in with GitHub feature working, let's explore
what this would've looked like with the async_trait
crate.
First up, the trait definition:
/// Something that can refresh credentials #[async_trait::async_trait] pub trait CredentialsRefresher { async fn refresh -> eyre
Because I started accepting donations via GitHub Sponsors, and because donating at the "Silver" tier or above gives you advance access to articles and your name in the credits, I need to interface with the GitHub API the same way I do the Patreon API.
Because I'd rather rely on third-party identity providers than provide my own sign up / log in / password forgotten / 2FA flow, user identifiers on my website are simply :
Now that my website is deployed as a container image, I wanted to give
nix a try. I'm still doing it the old-fashioned way right
now: with a Dockerfile
, running cargo
in a "builder" image, copying stuff
out of there into a slimmer image (that still has an Ubuntu base, even though
distroless images are a
thing now).
But why?
I was mostly interested in nix because some parts of my website have pretty big native dependencies. itself mostly relies on sqlite3 and some JS engine (used to be quickjs, currently duktape because MSVC Windows builds). But the asset processing pipeline, (which I'd like to integrate with at some point) has a bunch more!
Go back to the homepage.