Make code less verbose
This commit is contained in:
parent
235419e900
commit
4d6e7dcf92
1 changed files with 6 additions and 10 deletions
|
@ -1,14 +1,9 @@
|
||||||
const INPUT: &str = include_str!("../../input/01a.txt");
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let nums = input();
|
println!("First solution: {}", count_increases(input()));
|
||||||
let count = count_increases(nums);
|
|
||||||
println!("First solution: {}", count);
|
|
||||||
|
|
||||||
let input: Vec<i32> = input().collect();
|
let input: Vec<i32> = input().collect();
|
||||||
let nums = input.windows(3).map(|w| w.iter().sum());
|
let nums = input.windows(3).map(|w| w.iter().sum());
|
||||||
let count = count_increases(nums);
|
println!("Second solution: {}", count_increases(nums));
|
||||||
println!("Second solution: {}", count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_increases(it: impl Iterator<Item = i32>) -> usize {
|
fn count_increases(it: impl Iterator<Item = i32>) -> usize {
|
||||||
|
@ -21,7 +16,6 @@ fn count_increases(it: impl Iterator<Item = i32>) -> usize {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = Some(n);
|
prev = Some(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,5 +23,7 @@ fn count_increases(it: impl Iterator<Item = i32>) -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn input() -> impl Iterator<Item = i32> {
|
fn input() -> impl Iterator<Item = i32> {
|
||||||
INPUT.lines().map(|l| l.parse::<i32>().unwrap())
|
include_str!("../../input/01a.txt")
|
||||||
}
|
.lines()
|
||||||
|
.map(|l| l.parse().unwrap())
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue