mirror of
https://gitlab.com/MisterBiggs/wordle-rs.git
synced 2025-08-05 13:11:33 +00:00
basic wordle solving capabilities
This commit is contained in:
61
src/main.rs
61
src/main.rs
@@ -1,18 +1,34 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let words = fs::read_to_string("./wordle.txt")
|
let mut words = fs::read_to_string("./wordle.txt")
|
||||||
.expect("Cannot read file.")
|
.expect("Cannot read file.")
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(|&word| word.len() == 5)
|
.filter(|&word| word.trim().len() == 5)
|
||||||
|
.map(|word| word.trim().to_owned().to_lowercase())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let needed = "kilis";
|
||||||
|
let banned = "pourane";
|
||||||
|
|
||||||
|
// let mut count: usize = 0;
|
||||||
|
|
||||||
|
words = words
|
||||||
|
.iter()
|
||||||
|
.filter(|word| check_valid(word, needed, banned))
|
||||||
.map(|word| word.to_owned())
|
.map(|word| word.to_owned())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let needed = "def";
|
let values = words
|
||||||
let banned = "abc";
|
.iter()
|
||||||
|
.map(|word| word_value(word))
|
||||||
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
for word in words {
|
let &max = values.iter().max().unwrap();
|
||||||
if check_valid(&word, needed, banned) {
|
|
||||||
|
println!("Total Words: {}\nBest Guesses:", words.len());
|
||||||
|
for (word, value) in words.iter().zip(values) {
|
||||||
|
if value == max {
|
||||||
println!("{}", word);
|
println!("{}", word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,14 +48,29 @@ fn check_banned(word: &String, banned: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_needed(word: &String, needed: &str) -> bool {
|
fn check_needed(word: &String, needed: &str) -> bool {
|
||||||
needed
|
for need in needed.chars() {
|
||||||
.chars()
|
if !word.contains(need) {
|
||||||
.filter(|&n| word.contains(n))
|
return false;
|
||||||
.collect::<String>()
|
}
|
||||||
.len()
|
}
|
||||||
== 5
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn word_value(word: &str) -> usize {
|
fn word_value(word: &String) -> usize {
|
||||||
// todo!()
|
let mut value: usize = 0;
|
||||||
// }
|
|
||||||
|
// Give value to vowels in word
|
||||||
|
let vowels = "aeiou";
|
||||||
|
for vowel in vowels.chars() {
|
||||||
|
if word.contains(vowel) {
|
||||||
|
value = value + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: reimplement after needs uses letter index
|
||||||
|
// if word.chars().last().unwrap() == 's' {
|
||||||
|
// value = value + 3;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user