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

20 lines
511 B

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