Skip to content

Instantly share code, notes, and snippets.

@0e4ef622
Last active December 3, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0e4ef622/b4d9b90182023e0176c6d13a77093ac2 to your computer and use it in GitHub Desktop.
Save 0e4ef622/b4d9b90182023e0176c6d13a77093ac2 to your computer and use it in GitHub Desktop.
AoC 2020 Day 3 min lines after rustfmt
pub fn part1(input: &str) -> impl std::fmt::Display {
input.lines().enumerate().fold(0, |a, x| {
a + (x.1.as_bytes()[(x.0 * 3) % x.1.len()] == b'#') as u32
})
}
pub fn part2(input: &str) -> impl std::fmt::Display {
(|f: &dyn Fn(_, _) -> _| f(1, 1) * f(3, 1) * f(5, 1) * f(7, 1) * f(1, 2))(&|x, y| {
input.lines().enumerate().fold(0, |a, (i, l)| {
a + (l.as_bytes()[i / y * x % l.len()] == b'#' && i % y == 0) as usize
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment