Skip to content

Commit

Permalink
feat: new challenge, hard english words to type
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Oct 5, 2023
1 parent 2f589d2 commit 2aa6a22
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/random/hard_words.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use rand::seq::IteratorRandom;
use rand::thread_rng;

pub fn random_hard_english_words(max: u32) -> String {
let mut random_words = String::new();
for _i in 0..max {
if let Some(word) = random_hard_words() {
random_words.push_str(word.as_str());
}
}

random_words.trim_end().into()
}

fn random_hard_words() -> Option<String> {
let mut rng = thread_rng();
let subs = [
"antidisestablishmentarianism",
"supercalifragilisticexpialidocious",
"pneumonoultramicroscopicsilicovolcanoconiosis",
"floccinaucinihilipilification",
"hippopotomonstrosesquipedaliophobia",
"worcestershire",
"entrepreneur",
"conscientious",
"unquestionably",
"labyrinth",
];
let sample = subs.iter().choose(&mut rng);

sample.map(|s| s.to_owned().to_owned())
}
11 changes: 10 additions & 1 deletion src/random/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use self::{
letters::random_letters_inner, rustfun::random_function, sentences::random_english_sentences,
symbols::random_symbols, words::random_english_words,
};
use crate::random::hard_words::random_hard_english_words;

mod hard_words;
mod letters;
mod rustfun;
mod sentences;
Expand All @@ -18,7 +20,7 @@ pub struct Algorithm {
pub random_function: &'static dyn Fn(u32) -> String,
}

pub const ALGS: [Algorithm; 5] = [
pub const ALGS: [Algorithm; 6] = [
Algorithm {
id: "letters",
version: "0.2",
Expand All @@ -33,6 +35,13 @@ pub const ALGS: [Algorithm; 5] = [
lang: "eng",
random_function: &random_english_words,
},
Algorithm {
id: "hard",
version: "0.1",
description: "hard english words to type",
lang: "english",
random_function: &random_hard_english_words,
},
Algorithm {
id: "sentences",
version: "0.1",
Expand Down

0 comments on commit 2aa6a22

Please sign in to comment.