1use crate::util::parse::*;
7
8type Input = Vec<Vec<u32>>;
9
10pub fn parse(input: &str) -> Input {
11 input
12 .lines()
13 .map(|line| {
14 let mut values: Vec<_> = line.iter_unsigned().collect();
15 values.sort_unstable();
16 values
17 })
18 .collect()
19}
20
21pub fn part1(input: &Input) -> u32 {
22 input.iter().map(|values| values.last().unwrap() - values.first().unwrap()).sum()
23}
24
25pub fn part2(input: &Input) -> u32 {
26 input
27 .iter()
28 .map(|values| {
29 for (i, &smaller) in values.iter().enumerate() {
30 for &larger in &values[i + 1..] {
31 if larger.is_multiple_of(smaller) {
32 return larger / smaller;
33 }
34 }
35 }
36 unreachable!()
37 })
38 .sum()
39}