diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:29:56 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:29:56 +0200 |
commit | 34c0aa87fada4bf3bc75ff0493e0876e65289697 (patch) | |
tree | 599148bcbb7f05941edfac5ab3454a878129e997 /2017/src/bin/day_2.rs | |
parent | 174772b5b8d9f5bf5e3c8e8152adfd89f0e83f6b (diff) | |
parent | c99848b907d2d63577ffdc81fc11a77e4d328a92 (diff) |
Merge branch '2017-main'
Diffstat (limited to '2017/src/bin/day_2.rs')
-rw-r--r-- | 2017/src/bin/day_2.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2017/src/bin/day_2.rs b/2017/src/bin/day_2.rs new file mode 100644 index 0000000..307029a --- /dev/null +++ b/2017/src/bin/day_2.rs @@ -0,0 +1,26 @@ +extern crate advent_of_code_2017; +use advent_of_code_2017::*; + +fn main() { + let args = AdventArgs::init(); + let sum = args.input.iter().map(|line| { + let splitline = parse_space_separated_ints(line).unwrap(); + + if args.part == 1 { + let max = splitline.iter().max().unwrap(); + let min = splitline.iter().min().unwrap(); + max-min + } else { + for i in 0..splitline.len() { + for j in 0..splitline.len() { + if i != j && splitline[i] % splitline[j] == 0 { + return splitline[i] / splitline[j]; + } + } + } + panic!("Didn't find a dividing one! {:?}", splitline) + } + }).sum::<i32>(); + + println!("Checksum is {}", sum); +} |