diff --git a/2017/rust/src/day_01.rs b/2017/rust/src/day_01.rs index 61971a6..fdd0cd2 100644 --- a/2017/rust/src/day_01.rs +++ b/2017/rust/src/day_01.rs @@ -1,5 +1,6 @@ use failure::*; +#[allow(dead_code)] pub fn solve(input: &str) -> Result { let input: Vec = input .trim() diff --git a/2017/rust/src/day_02.rs b/2017/rust/src/day_02.rs index 2eafa08..f8d495a 100644 --- a/2017/rust/src/day_02.rs +++ b/2017/rust/src/day_02.rs @@ -4,16 +4,20 @@ pub fn solve(input: &str) -> Result { Ok( input .trim() - .split("\n") + .split('\n') .map(|row| { - let row: Vec<_> = row.split("\t") + row.split('\t') .map(|x| x.parse::().unwrap()) - .collect(); - let min = row.iter().min().unwrap(); - let max = row.iter().max().unwrap(); - max - min + .collect::>() }) + .map(|row| checksum(&row)) .sum::() .to_string(), ) } + +fn checksum(row: &[usize]) -> usize { + let min = row.iter().min().unwrap(); + let max = row.iter().max().unwrap(); + max - min +}