You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2017/rust/src/day_02.rs

24 lines
546 B

use failure::*;
pub fn solve(input: &str) -> Result<String, Error> {
Ok(
input
.trim()
.split('\n')
.map(|row| {
row.split('\t')
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>()
})
.map(|row| checksum(&row))
.sum::<usize>()
.to_string(),
)
}
fn checksum(row: &[usize]) -> usize {
let min = row.iter().min().unwrap();
let max = row.iter().max().unwrap();
max - min
}