[2017][rust][2.x]

sorbet
Alpha Chen 7 years ago
parent 7d36ddd8fe
commit 8d26a5df6a

@ -1,5 +1,6 @@
use failure::*;
#[allow(dead_code)]
pub fn solve(input: &str) -> Result<String, Error> {
let input: Vec<u32> = input
.trim()

@ -4,16 +4,20 @@ pub fn solve(input: &str) -> Result<String, Error> {
Ok(
input
.trim()
.split("\n")
.split('\n')
.map(|row| {
let row: Vec<_> = row.split("\t")
row.split('\t')
.map(|x| x.parse::<usize>().unwrap())
.collect();
let min = row.iter().min().unwrap();
let max = row.iter().max().unwrap();
max - min
.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
}

Loading…
Cancel
Save