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