day(01): use ‹Input›/‹Output› types
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
43e6948cd7
commit
27db9907d4
1 changed files with 7 additions and 4 deletions
|
@ -4,7 +4,10 @@ use color_eyre::eyre::Result;
|
||||||
use tracing::*;
|
use tracing::*;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
fn n_biggest(n: usize, input: &[i32]) -> i32 {
|
type Input = Vec<i32>;
|
||||||
|
type Output = i32;
|
||||||
|
|
||||||
|
fn n_biggest(n: usize, input: &Input) -> Output {
|
||||||
let mut calories: Vec<i32> = Vec::new();
|
let mut calories: Vec<i32> = Vec::new();
|
||||||
|
|
||||||
let last_elf = input.iter().fold(0, |a, &x| {
|
let last_elf = input.iter().fold(0, |a, &x| {
|
||||||
|
@ -21,15 +24,15 @@ fn n_biggest(n: usize, input: &[i32]) -> i32 {
|
||||||
calories.iter().rev().take(n).sum()
|
calories.iter().rev().take(n).sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part_1(input: &[i32]) -> i32 {
|
fn part_1(input: &Input) -> Output {
|
||||||
n_biggest(1_usize, input)
|
n_biggest(1_usize, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part_2(input: &[i32]) -> i32 {
|
fn part_2(input: &Input) -> Output {
|
||||||
n_biggest(3_usize, input)
|
n_biggest(3_usize, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_input(pathname: &str) -> Vec<i32> {
|
fn parse_input(pathname: &str) -> Input {
|
||||||
file_to_lines(pathname)
|
file_to_lines(pathname)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| if s.is_empty() { -1 } else { s.parse().unwrap() })
|
.map(|s| if s.is_empty() { -1 } else { s.parse().unwrap() })
|
||||||
|
|
Loading…
Reference in a new issue