Last active
December 3, 2020 20:46
-
-
Save 0e4ef622/b4d9b90182023e0176c6d13a77093ac2 to your computer and use it in GitHub Desktop.
AoC 2020 Day 3 min lines after rustfmt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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