cant figure 19 out
This commit is contained in:
+29
-28
@@ -36,42 +36,41 @@ fn main() {
|
||||
|
||||
part1(conversions, &separate); // 576
|
||||
|
||||
main2();
|
||||
_part2(conversions, formula);
|
||||
// main2();
|
||||
}
|
||||
|
||||
// fn _part2(conversions: &[(&str, &str)], formula: &str) {
|
||||
// let mut rng = rand::rng();
|
||||
fn _part2(conversions: &[(&str, &str)], formula: &str) {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
// let mut rand_conversions = conversions.to_vec();
|
||||
let mut rand_conversions = conversions.to_vec();
|
||||
// let mut old_conversion_count = 10000; // large
|
||||
// let mut conversion_count;
|
||||
let mut conversion_count;
|
||||
|
||||
// loop {
|
||||
// conversion_count = 0;
|
||||
// let mut formula_replaced = formula.to_string();
|
||||
'outer: loop {
|
||||
let mut current = formula.to_string();
|
||||
|
||||
// loop {
|
||||
// let old_formula_replaced = formula_replaced.clone();
|
||||
conversion_count = 0;
|
||||
rand_conversions.shuffle(&mut rng);
|
||||
|
||||
// rand_conversions.shuffle(&mut rng);
|
||||
while current != "e" {
|
||||
let mut reduced_this_round = false;
|
||||
for (short, long) in conversions {
|
||||
if let Some(pos) = current.find(long) {
|
||||
conversion_count += 1;
|
||||
reduced_this_round = true;
|
||||
current.replace_range(pos..pos + long.len(), short);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for (short, long) in conversions {
|
||||
// if formula_replaced.contains(long) {
|
||||
// conversion_count += 1;
|
||||
// }
|
||||
|
||||
// formula_replaced = replace_any(formula_replaced, long, short, &mut rng);
|
||||
// }
|
||||
// if formula_replaced == old_formula_replaced {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if conversion_count < old_conversion_count {
|
||||
// println!("{conversion_count}");
|
||||
// old_conversion_count = conversion_count;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if !reduced_this_round {
|
||||
continue 'outer;
|
||||
}
|
||||
}
|
||||
println!("{conversion_count}");
|
||||
}
|
||||
}
|
||||
|
||||
// fn replace_any(input: String, long: &str, short: &str, rng: &mut ThreadRng) -> String {
|
||||
// let haystack: Vec<_> = input.chars().collect();
|
||||
@@ -146,6 +145,8 @@ fn part1(conversions: &[(&str, &str)], formula: &[String]) {
|
||||
|
||||
use std::fs;
|
||||
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
/// A single replacement rule as it appears in the puzzle input: `from => to`.
|
||||
struct Rule {
|
||||
from: String,
|
||||
|
||||
Reference in New Issue
Block a user