Created
April 12, 2022 05:29
-
-
Save CIAvash/a46c7e386789f25e3ae1d1b3d9f6a14d to your computer and use it in GitHub Desktop.
Manual 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
#!/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