day(01): factor out parsing
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
604bc5d6a9
commit
0f6c1af251
1 changed files with 9 additions and 8 deletions
|
@ -61,6 +61,13 @@ fn part_2(input: &[i32]) -> i32 {
|
|||
calories.iter().rev().take(3).sum()
|
||||
}
|
||||
|
||||
fn parse_input(pathname: &str) -> Vec<i32> {
|
||||
file_to_lines(pathname)
|
||||
.iter()
|
||||
.map(|s| if s.is_empty() { -1 } else { s.parse().unwrap() })
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
|
@ -71,14 +78,8 @@ fn main() {
|
|||
.compact()
|
||||
.init();
|
||||
|
||||
let sample: Vec<i32> = file_to_lines("samples/day01.txt")
|
||||
.iter()
|
||||
.map(|s| if s.is_empty() { -1 } else { s.parse().unwrap() })
|
||||
.collect();
|
||||
let input: Vec<i32> = file_to_lines("inputs/day01.txt")
|
||||
.iter()
|
||||
.map(|s| if s.is_empty() { -1 } else { s.parse().unwrap() })
|
||||
.collect();
|
||||
let sample = parse_input("samples/day01.txt");
|
||||
let input = parse_input("inputs/day01.txt");
|
||||
|
||||
assert_eq!(part_1(&sample), 24000);
|
||||
info!("Part 1: {}", part_1(&input));
|
||||
|
|
Loading…
Reference in a new issue