Skip to content

Commit

Permalink
maybe working 100% for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bozdoz committed Jan 16, 2024
1 parent b42e09e commit e5da307
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions day-25/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,16 @@ fn bfs<'a>(akey: &'a str, bkey: &'a str, components: &'a Components) -> Vec<(&'a

// ? can we check if any of these are in bkey's links?
for next in links {
let mut path = vec![];
let mut path = state.path.clone();

// TIL
path.extend(state.path.iter());
path.push((current, *next));

if *next == bkey {
// done
return path;
}

let mut visited = HashSet::new();

for a in state.visited.iter() {
visited.insert(*a);
}
let mut visited = state.visited.clone();

visited.insert(current);

Expand Down Expand Up @@ -119,20 +113,20 @@ fn bfs_everywhere<'a>(components: &'a Components) -> Vec<(&'a str, &'a str)> {

// TODO: we can cache bfs from a to each val
for (i, akey) in keys.iter().enumerate() {
for bkey in keys.iter().skip(i+1) {
if distances.contains_key(&Edge::from(akey, bkey)) {
for (j, bkey) in keys.iter().enumerate() {
if i == j {
continue;
}
// bfs
let path = bfs(akey, bkey, components);

for (d, paths) in path.iter().rev().enumerate() {
for paths in path.iter() {
// sorting for hash
let v = Edge::from(paths.0, paths.1);

distances.entry(v).and_modify(|x| {
*x += d+1;
}).or_insert(d+1);
*x += 1;
}).or_insert(1);
}
}
}
Expand Down

0 comments on commit e5da307

Please sign in to comment.