Skip to content

Commit

Permalink
refactor(23/2024): simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
manhunto committed Dec 27, 2024
1 parent ce2c9dc commit 1c1bad1
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/solutions/year2024/day23.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::solutions::Solution;
use std::collections::{HashMap, HashSet};
use itertools::Itertools;
use std::collections::HashMap;

pub struct Day23;

Expand All @@ -19,25 +20,22 @@ impl Solution for Day23 {
})
.collect();

let mut sets: HashSet<[&str; 3]> = HashSet::new();
connections
.iter()
.flat_map(|(a, b)| {
let a_neighbours = neighbours.get(a).unwrap();
let b_neighbours = neighbours.get(b).unwrap();

connections.iter().for_each(|(a, b)| {
let a_neighbours = neighbours.get(a).unwrap();
let b_neighbours = neighbours.get(b).unwrap();

let intersection: Vec<_> = a_neighbours
.iter()
.filter(|x| b_neighbours.contains(x))
.collect();

intersection.iter().for_each(|c| {
let mut set = [*a, *b, *c];
set.sort();
sets.insert(set);
});
});

sets.iter()
a_neighbours
.iter()
.filter(|x| b_neighbours.contains(x))
.map(|c| {
let mut set = [*a, *b, *c];
set.sort();
set
})
})
.unique()
.filter(|set| set.iter().any(|c| c.starts_with("t")))
.count()
.to_string()
Expand Down

0 comments on commit 1c1bad1

Please sign in to comment.