-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.rs
More file actions
22 lines (21 loc) · 545 Bytes
/
main.rs
File metadata and controls
22 lines (21 loc) · 545 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub fn main() {
let subs = include_str!("../input.txt")
.split(',')
.map(|n| n.parse().unwrap())
.collect::<Vec<_>>();
println!(
"{}",
(subs.iter().sum::<i32>() / subs.len() as i32..)
.take(2)
.map(|t| {
subs.iter()
.map(|n| {
let d = (n - t).abs();
d * (d + 1) / 2
})
.sum::<i32>()
})
.min()
.unwrap()
);
}