-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
32 lines (27 loc) · 1.07 KB
/
main.rs
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
32
#![feature(iter_collect_into)]
mod universe;
mod galaxy;
use crate::universe::Universe;
fn main() {
let run_part = |universe: &mut Universe, multiplier:usize| -> usize {
universe.expand(multiplier);
universe.clusters
.iter()
.enumerate()
.map(|(i, from)| {
universe.clusters
.iter()
.skip(i + 1)
.map(|to| from.distance_to(to))
.sum::<usize>()
})
.sum::<usize>()
};
let input = std::fs::read_to_string("src/bin/day11/input.txt").expect("Ops!");
let mut universe = input.parse::<Universe>().expect("Failed to parse Universe!");
let t = std::time::Instant::now();
println!("Part 1 - Sum of shortest paths: {} - {:?}", run_part(&mut universe,2), t.elapsed());
let mut universe = input.parse::<Universe>().expect("Failed to parse Universe!");
let t = std::time::Instant::now();
println!("Part 2 - Sum of shortest paths: {} - {:?}", run_part(&mut universe, 1_000_000), t.elapsed());
}