Skip to content

Instantly share code, notes, and snippets.

@CIAvash
Created April 12, 2022 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CIAvash/a46c7e386789f25e3ae1d1b3d9f6a14d to your computer and use it in GitHub Desktop.
Save CIAvash/a46c7e386789f25e3ae1d1b3d9f6a14d to your computer and use it in GitHub Desktop.
Manual wordle solver!
#!/usr/bin/env raku
#| Manual wordle solver!
unit sub MAIN (Str :c(:$contains), Str :e(:$exclude), Str :a(:$at), Str :n(:$not-at));
USAGE() and exit unless @*ARGS;
.put for '/usr/share/dict/words'.IO.lines.grep: {
.chars == 5
and /^<:Ll>/
and .contains: all «$contains»
and .contains: none «$exclude»
and ($at ?? .&compare_letters_at: $at, &[eq] !! True)
and ($not-at ?? .&compare_letters_at: $not-at, &[ne] !! True)
}
sub USAGE {
put "$*USAGE\n";
put "Example:";
put " wordle-solver.raku --contains 'o a l' --exclude 's m i e p t c h b u n d' --at '2 o' --not-at '2 a, 4 l'";
}
sub compare_letters_at (Str:D $word, Str:D $at, &compare --> Bool:D) {
[and] $at.split(',').map: { compare $word.comb[.words[0] - 1], .words[1] }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment