summaryrefslogtreecommitdiff
path: root/src/bin/day_25.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/day_25.rs')
-rw-r--r--src/bin/day_25.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/bin/day_25.rs b/src/bin/day_25.rs
index 4301af4..9e74f49 100644
--- a/src/bin/day_25.rs
+++ b/src/bin/day_25.rs
@@ -9,10 +9,39 @@ use std::path::PathBuf;
fn main() -> Result<(), Box<Error>> {
let input = read_file(&PathBuf::from("inputs/25.txt"))?;
- println!("Input: {:?}", input);
-
+ let mut constellations: Vec<Vec<Vec<i32>>> = input.iter()
+ .map(|line| line.split(',').map(|x| x.parse().unwrap()).collect::<Vec<_>>())
+ .map(|points| vec!(points))
+ .collect();
+ // debug!(constellations);
+ while join_constellations(&mut constellations) {
+ }
+ debug!(constellations.len());
+
Ok(())
}
+
+fn distance(xs: &[i32], ys: &[i32]) -> i32 {
+ xs.iter().zip(ys.iter()).map(|(x,y)| (x - y).abs()).sum()
+}
+
+fn join_constellations(constellations: &mut Vec<Vec<Vec<i32>>>) -> bool {
+ for i in 0..constellations.len()-1 {
+ for j in i+1..constellations.len() {
+ let connected = constellations[i].iter().any(|ci| {
+ constellations[j].iter().any(|cj| {
+ distance(&ci, &cj) <= 3
+ })
+ });
+ if connected {
+ let mut to_join = constellations.remove(j);
+ constellations[i].append(&mut to_join);
+ return true;
+ }
+ }
+ }
+ false
+}