Clean up day19
This commit is contained in:
parent
cee0f7c935
commit
ea53bf8a14
@ -54,22 +54,11 @@ fn count_possible(
|
|||||||
if let Some(res) = cache.get(design) {
|
if let Some(res) = cache.get(design) {
|
||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
let mut count = 0;
|
let count = available_patterns
|
||||||
for pattern in available_patterns {
|
.iter()
|
||||||
if pattern.len() > design.len() {
|
.filter(|p| design.starts_with(p))
|
||||||
continue;
|
.map(|p| count_possible(&design[p.len()..], available_patterns, cache))
|
||||||
}
|
.sum();
|
||||||
let mut matches = true;
|
|
||||||
for i in 0..pattern.len() {
|
|
||||||
if design[i] != pattern[i] {
|
|
||||||
matches = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if matches {
|
|
||||||
count += count_possible(&design[pattern.len()..], available_patterns, cache);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache.insert(design.to_vec(), count);
|
cache.insert(design.to_vec(), count);
|
||||||
count
|
count
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user