Skip to content

Commit

Permalink
Merge pull request #69 from ephemient/rs/minor-cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient authored Dec 9, 2024
2 parents a7aa46d + c12a644 commit a639744
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
5 changes: 1 addition & 4 deletions rs/src/day7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ pub fn part2(data: &str) -> usize {
values.push(x / y);
}
if x > y {
let mut d = 10;
while d <= y {
d *= 10;
}
let d = 10usize.pow(y.checked_ilog10().unwrap_or(0) + 1);
if x % d == y {
values.push(x / d);
}
Expand Down
19 changes: 8 additions & 11 deletions rs/src/day8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::BTreeSet;
use std::iter;
use std::iter::{once, successors};

use itertools::Itertools;

Expand Down Expand Up @@ -34,14 +34,11 @@ where
.filter(move |point1| point0 != *point1)
.flat_map(|(y1, x1)| {
let (dy, dx) = (*y1 as isize - *y0 as isize, *x1 as isize - *x0 as isize);
multiples
.clone()
.map(move |i| {
y1.checked_add_signed(i * dy)
.filter(|y| *y < height)
.zip(x1.checked_add_signed(i * dx).filter(|x| *x < width))
})
.while_some()
multiples.clone().map_while(move |i| {
y1.checked_add_signed(i * dy)
.zip(x1.checked_add_signed(i * dx))
.filter(|(y, x)| *y < height && *x < width)
})
})
})
})
Expand All @@ -50,11 +47,11 @@ where
}

pub fn part1(data: &str) -> usize {
solve(data, iter::once(1))
solve(data, once(1))
}

pub fn part2(data: &str) -> usize {
solve(data, iter::successors(Some(0), |i| Some(i + 1)))
solve(data, successors(Some(0), |i| Some(i + 1)))
}

#[cfg(test)]
Expand Down

0 comments on commit a639744

Please sign in to comment.