|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|