With regex and dedup final list
This commit is contained in:
parent
06aedc226e
commit
810b17894d
|
|
@ -5,3 +5,4 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.47", features = ["derive"] }
|
||||
regex = "1.11.2"
|
||||
|
|
|
|||
48
src/main.rs
48
src/main.rs
|
|
@ -4,6 +4,7 @@
|
|||
// find better weight
|
||||
#![allow(dead_code)]
|
||||
use clap::Parser;
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
|
|
@ -16,6 +17,14 @@ struct Args {
|
|||
#[arg(short, long)]
|
||||
r#in: Option<String>,
|
||||
|
||||
/// Has these position, with _ for any and a letter for the letter
|
||||
#[arg(short, long)]
|
||||
pos: Option<String>,
|
||||
|
||||
/// Depth of the trying process
|
||||
#[arg(short, long, default_value_t = 5)]
|
||||
depth: usize,
|
||||
|
||||
/// Doesnt contains these letters
|
||||
#[arg(short, long)]
|
||||
out: Option<String>,
|
||||
|
|
@ -119,7 +128,7 @@ impl Display for Wordlist {
|
|||
.map(|w| w.origin.clone())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
write!(f, "{}", o)
|
||||
write!(f, "{o}")
|
||||
}
|
||||
}
|
||||
impl Wordlist {
|
||||
|
|
@ -190,9 +199,10 @@ fn backtrack_best(
|
|||
origin_list: &Wordlist,
|
||||
origin_weights: &Weightlist,
|
||||
mut total_score: TotalScore,
|
||||
depth: usize,
|
||||
letter_depth: usize,
|
||||
guess_depth: usize,
|
||||
) -> TotalScore {
|
||||
if depth == 0 {
|
||||
if letter_depth == 0 {
|
||||
TotalScore::default()
|
||||
} else {
|
||||
// println!("Starts new track: TS[{:?}]", &total_score);
|
||||
|
|
@ -204,13 +214,19 @@ fn backtrack_best(
|
|||
|
||||
// Pick n bests word, backtrack their score and return the best of the best results
|
||||
let mut list_guesses = Vec::new();
|
||||
for i in 0..15 {
|
||||
for i in 0..guess_depth {
|
||||
let guess = list.guess(i);
|
||||
// println!("Guess: {:?}", guess);
|
||||
let mut weights = origin_weights.clone();
|
||||
weights.remove_word(&guess);
|
||||
// Backtrack the implied scores
|
||||
let bb = backtrack_best(&list, &weights, total_score.clone(), depth - 1);
|
||||
let bb = backtrack_best(
|
||||
&list,
|
||||
&weights,
|
||||
total_score.clone(),
|
||||
letter_depth - 1,
|
||||
guess_depth,
|
||||
);
|
||||
let mut v = bb.words.clone();
|
||||
v.push(guess.clone());
|
||||
list_guesses.push(TotalScore {
|
||||
|
|
@ -228,7 +244,7 @@ fn backtrack_best(
|
|||
}
|
||||
}
|
||||
fn main() {
|
||||
let wl = Wordlist::new(read_list("./sgb-words.txt"));
|
||||
let wl = Wordlist::new(read_list("./wordlists/final.txt"));
|
||||
let weights = wl.make_weights();
|
||||
|
||||
let args = Args::parse();
|
||||
|
|
@ -236,24 +252,36 @@ fn main() {
|
|||
println!(
|
||||
"Best {}: {:#?}",
|
||||
number,
|
||||
backtrack_best(&wl, &weights, TotalScore::default(), number)
|
||||
backtrack_best(&wl, &weights, TotalScore::default(), number, args.depth)
|
||||
);
|
||||
}
|
||||
if let Some(with) = args.r#in {
|
||||
let mut list = Wordlist::new(
|
||||
wl.inner
|
||||
.into_iter()
|
||||
.filter(|w| with.chars().into_iter().all(|c| w.origin.contains(c)))
|
||||
.filter(|w| with.chars().all(|c| w.origin.contains(c)))
|
||||
.collect(),
|
||||
);
|
||||
if let Some(without) = args.out {
|
||||
list = Wordlist::new(
|
||||
list.inner
|
||||
.into_iter()
|
||||
.filter(|w| without.chars().into_iter().all(|c| !w.origin.contains(c)))
|
||||
.filter(|w| without.chars().all(|c| !w.origin.contains(c)))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
println!("{}", list);
|
||||
|
||||
if let Some(pos) = args.pos {
|
||||
list = Wordlist::new(
|
||||
list.inner
|
||||
.into_iter()
|
||||
.filter(|w| {
|
||||
let re = Regex::new(&pos).unwrap();
|
||||
re.is_match(&w.origin)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
println!("{list}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
5752
wordlists/final.txt
5752
wordlists/final.txt
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue