[2017][rust][2.x]

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

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

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

Loading…
Cancel
Save