1
0
Fork 0

day(01): use ‹Input›/‹Output› types

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-12-02 10:23:52 +01:00
parent 43e6948cd7
commit 27db9907d4
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -4,7 +4,10 @@ use color_eyre::eyre::Result;
use tracing::*;
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 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()
}
fn part_1(input: &[i32]) -> i32 {
fn part_1(input: &Input) -> Output {
n_biggest(1_usize, input)
}
fn part_2(input: &[i32]) -> i32 {
fn part_2(input: &Input) -> Output {
n_biggest(3_usize, input)
}
fn parse_input(pathname: &str) -> Vec<i32> {
fn parse_input(pathname: &str) -> Input {
file_to_lines(pathname)
.iter()
.map(|s| if s.is_empty() { -1 } else { s.parse().unwrap() })