-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
31 lines (25 loc) · 801 Bytes
/
main.rs
File metadata and controls
31 lines (25 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").expect("Could not read file");
let mut total1 = 0;
let mut total2 = 0;
for l in input.lines() {
let mut p = l
.split_ascii_whitespace()
.map(|i| i.parse::<u64>().unwrap())
.collect::<Vec<_>>();
// sorting is faster than comparing individual elements against each other
p.sort_unstable();
total1 += p.last().unwrap() - p.first().unwrap();
'outer: for (i, &a) in p.iter().enumerate() {
for &b in p.iter().skip(i + 1) {
if b % a == 0 {
total2 += b / a;
break 'outer;
}
}
}
}
println!("{total1}");
println!("{total2}");
}