Day 1
This commit is contained in:
12
src/day1.rs
12
src/day1.rs
@@ -1,5 +1,15 @@
|
||||
|
||||
|
||||
pub fn run(input: &str) {
|
||||
|
||||
let step_list = input.lines()
|
||||
.map(|l| l.replace("L", "").replace("R", "-").parse::<i32>().unwrap());
|
||||
let counted = step_list.scan(50, |dial, steps| {
|
||||
let at_0 = (*dial..(*dial + steps))
|
||||
.chain((*dial + steps + 1)..=*dial)
|
||||
.filter(|num| *num % 100 == 0).count();
|
||||
*dial += steps;
|
||||
Some((*dial % 100 == 0, at_0))
|
||||
});
|
||||
println!("Part 1: {}", counted.clone().filter(|(is_0, _)| *is_0).count());
|
||||
println!("Part 2: {}", counted.fold(0, |acc, num| acc + num.1));
|
||||
}
|
||||
|
||||
4499
src/inputs/day1.txt
4499
src/inputs/day1.txt
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ mod day1;
|
||||
|
||||
const CHOICES: [&str; 2] = [
|
||||
"Exit",
|
||||
"Day 1: ",
|
||||
"Day 1: Secret Entrance",
|
||||
];
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user