Skip to content

Commit

Permalink
README update & fixed search
Browse files Browse the repository at this point in the history
  • Loading branch information
cqb13 committed Oct 5, 2024
1 parent e4a5bdb commit 3401651
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@ A CLI tool that finds words of a specific length with letters in a specific loca
I use this for building crosswords

https://github.com/user-attachments/assets/e3393b22-b91d-45f2-ac16-19c11be40fc2

## Installation

### Build from Source

Clone the repository and build the project using [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html):

```sh
git clone https://github.com/Talon-Games/word-finder
cd word-finder
cargo build --release
# The binary will be located at target/release/word-finder
```

To add the binary to your PATH, run:

```sh
cargo install --path .
```

### Pre-built Binaries

Pre-built binaries are available for Windows, macOS, and Linux on the [releases page](https://github.com/Talon-Games/word-finder/releases).
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ fn search() {
println!("--------------------------------------");
}

fn find_words_from_list(word_length: i32, letter_requirements: Vec<String>) -> Vec<&'static str> {
fn find_words_from_list(word_length: i32, letter_requirements: Vec<String>) -> Vec<String> {
let words_file: Vec<&str> = include_str!("./words.txt")
.lines()
.map(|line| line.trim())
.filter(|line| !line.is_empty() && line.len() == word_length as usize)
.filter(|line| {
!line.is_empty()
&& line.split("::").collect::<Vec<&str>>()[0].trim().len() == word_length as usize
})
.collect();

let mut fitting_words = Vec::new();

for word in words_file {
for line in words_file {
let mut valid = true;
let line: Vec<&str> = line.split("::").collect();
let word = line[0].trim();
let mut definition = line[1].trim();
for (i, letter) in word
.trim()
.split("")
.into_iter()
.filter(|s| !s.is_empty())
Expand All @@ -73,7 +80,11 @@ fn find_words_from_list(word_length: i32, letter_requirements: Vec<String>) -> V
continue;
}

fitting_words.push(&*word)
if definition.len() == 0 {
definition = "[no definition]"
}

fitting_words.push(format!("{} - {}", word, definition))
}

fitting_words
Expand Down

0 comments on commit 3401651

Please sign in to comment.