Created
February 9, 2022 13:23
-
-
Save libbkmz/c91bd574f1991445c3c45d2e5ae297ac to your computer and use it in GitHub Desktop.
Simple rust wordle solver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "wobli" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::{prelude::*, BufReader}; | |
const NULL_CHAR: char = '\0'; | |
static LETTERS: &[char] = &['m', 'o']; | |
static POS_LETTERS: &[char] = &[NULL_CHAR, NULL_CHAR, 'm', NULL_CHAR, NULL_CHAR]; | |
static NOT_POS: &[&[char]] = &[&[], &['o'], &[], &[], &[]]; | |
fn main() { | |
let file = File::open("/usr/share/dict/words").unwrap(); | |
let reader = BufReader::new(file); | |
let mut counter: u64 = 0; | |
'outer: for line in reader.lines() { | |
let line = line.unwrap(); | |
if line.len() != 5 { | |
continue; | |
} | |
for ch in LETTERS { | |
if line.contains(*ch) { | |
continue | |
} else { | |
continue 'outer; | |
} | |
} | |
for (pch, ch) in POS_LETTERS.iter().zip(line.chars()) { | |
if *pch == NULL_CHAR { | |
continue | |
} | |
if *pch != ch { | |
continue 'outer; | |
} | |
} | |
for (list_ch, ch) in NOT_POS.iter().zip(line.chars()) { | |
for not_ch in *list_ch { | |
if ch == *not_ch { | |
continue 'outer; | |
} | |
} | |
} | |
counter+=1; | |
println!("{}", line); | |
} | |
println!("{}", counter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment