cant figure 19 out

This commit is contained in:
timeshifter
2026-06-25 22:22:33 +02:00
parent badb2390bb
commit f6e4d9cea0
+30 -29
View File
@@ -36,42 +36,41 @@ fn main() {
part1(conversions, &separate); // 576 part1(conversions, &separate); // 576
main2(); _part2(conversions, formula);
// main2();
} }
// fn _part2(conversions: &[(&str, &str)], formula: &str) { fn _part2(conversions: &[(&str, &str)], formula: &str) {
// let mut rng = rand::rng(); 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 old_conversion_count = 10000; // large
// let mut conversion_count; let mut conversion_count;
// loop { 'outer: loop {
// conversion_count = 0; let mut current = formula.to_string();
// let mut formula_replaced = formula.to_string();
// loop { conversion_count = 0;
// let old_formula_replaced = formula_replaced.clone(); 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 !reduced_this_round {
// if formula_replaced.contains(long) { continue 'outer;
// conversion_count += 1; }
// } }
println!("{conversion_count}");
// 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;
// }
// }
// }
// fn replace_any(input: String, long: &str, short: &str, rng: &mut ThreadRng) -> String { // fn replace_any(input: String, long: &str, short: &str, rng: &mut ThreadRng) -> String {
// let haystack: Vec<_> = input.chars().collect(); // let haystack: Vec<_> = input.chars().collect();
@@ -146,6 +145,8 @@ fn part1(conversions: &[(&str, &str)], formula: &[String]) {
use std::fs; use std::fs;
use rand::seq::SliceRandom;
/// A single replacement rule as it appears in the puzzle input: `from => to`. /// A single replacement rule as it appears in the puzzle input: `from => to`.
struct Rule { struct Rule {
from: String, from: String,