fix failing tests
This commit is contained in:
14 files changed
+51
-149
No files matched your search
+5
-22
@@ -27,11 +27,7 @@ fn find_path(cur: &str, goal: &str, edges: &Edges) -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
fn mark_paths<'a>(
|
||||
cur: &'a str,
|
||||
edges: &'a Edges,
|
||||
mut reachable: FxHashSet<&'a str>,
|
||||
) -> FxHashSet<&'a str> {
|
||||
fn mark_paths<'a>(cur: &'a str, edges: &'a Edges, mut reachable: FxHashSet<&'a str>) -> FxHashSet<&'a str> {
|
||||
reachable.insert(cur);
|
||||
if let Some(nexts) = edges.get(cur) {
|
||||
for n in nexts {
|
||||
@@ -43,12 +39,7 @@ fn mark_paths<'a>(
|
||||
reachable
|
||||
}
|
||||
|
||||
fn count_paths_impl<'a>(
|
||||
cur: &'a str,
|
||||
goal: &str,
|
||||
edges: &'a Edges,
|
||||
memo: &mut FxHashMap<&'a str, u64>,
|
||||
) -> u64 {
|
||||
fn count_paths_impl<'a>(cur: &'a str, goal: &str, edges: &'a Edges, memo: &mut FxHashMap<&'a str, u64>) -> u64 {
|
||||
if cur == goal {
|
||||
return 1;
|
||||
}
|
||||
@@ -57,10 +48,7 @@ fn count_paths_impl<'a>(
|
||||
}
|
||||
|
||||
if let Some(nexts) = edges.get(cur) {
|
||||
let ret = nexts
|
||||
.iter()
|
||||
.map(|n| count_paths_impl(n, goal, edges, memo))
|
||||
.sum();
|
||||
let ret = nexts.iter().map(|n| count_paths_impl(n, goal, edges, memo)).sum();
|
||||
memo.insert(cur, ret);
|
||||
ret
|
||||
} else {
|
||||
@@ -92,9 +80,7 @@ fn part2_memo(edges: &Edges) -> u64 {
|
||||
//
|
||||
// this is our performance implementation though and it's faster to not do that work. we do the posterity for the
|
||||
// naive solution
|
||||
count_paths("svr", "fft", edges)
|
||||
* count_paths("fft", "dac", edges)
|
||||
* count_paths("dac", "out", edges)
|
||||
count_paths("svr", "fft", edges) * count_paths("fft", "dac", edges) * count_paths("dac", "out", edges)
|
||||
}
|
||||
|
||||
#[aoc(day11, part2, NaiveDfs)]
|
||||
@@ -110,10 +96,7 @@ fn part2(edges: &Edges) -> u64 {
|
||||
let mut reachable_fft = mark_paths("fft", edges, FxHashSet::default());
|
||||
reachable_fft = mark_paths("fft", &rev, reachable_fft);
|
||||
|
||||
let reachable: FxHashSet<&str> = reachable_dac
|
||||
.intersection(&reachable_fft)
|
||||
.copied()
|
||||
.collect();
|
||||
let reachable: FxHashSet<&str> = reachable_dac.intersection(&reachable_fft).copied().collect();
|
||||
|
||||
let unreachable: FxHashSet<&str> = FxHashSet::from_iter(edges.keys().map(|k| k.as_str()))
|
||||
.difference(&reachable)
|
||||
|
||||
Reference in new issue
Block a user