Skip to content

Commit

Permalink
day18: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pedantic79 committed Jan 3, 2024
1 parent bc6463b commit e49b357
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/day18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,27 @@ pub fn generator(input: &str) -> Vec<(DigDir, DigDir)> {

fn solve<'a>(itr: impl IntoIterator<Item = &'a DigDir>) -> i64 {
let mut width = 0;
let mut area = 1;
let mut area = 1; // width of the digger

for digdir in itr {
let DigDir { dir: d, amt: l } = digdir;

match d {
Dir::Right => {
width += l;
area += l;
}
Dir::Down => {
area += (width + 1) * l; // the +1 is for the width of the digger
}
Dir::Up => {
area -= width * l;
}
Dir::Left => {
// we don't add to area, because going left won't be included
// until we go Down
width -= l;
}
Dir::Down => {
area += (width + 1) * l;
}
Dir::Right => {
width += l;
area += l;
}
}
}

Expand Down

0 comments on commit e49b357

Please sign in to comment.