Anagram generator: Difference between revisions

→‎{{header|Raku}}: Add missing word, Made dictionary used a command line directive
(New draft task and Raku example)
 
(→‎{{header|Raku}}: Add missing word, Made dictionary used a command line directive)
Line 7:
It is not necessary to (only) generate anagrams that make sense. That is a hard problem, much more difficult than can realistically be done in a small program; though again, if you feel the need, you are invited to amaze your peers.
 
In general, try to form phrases made up of longer words. Feel free to manually reorder output words or add punctuation and/or case changes to get a better meaning.
 
 
Line 33:
Using the unixdict.txt word file by default.
 
<lang perl6>unit sub MAIN ($in is copy = '', :$dict = 'unixdict.txt');
 
say 'Enter a word or phrase to be anagramed. (Loading dictionary)' unless $in.chars;
 
# Load the words into a word / Bag hash
my %words = 'unixdict.txt'$dict.IO.slurp.lc.words.race.map: { .comb(/\w/).join => .comb(/\w/).Bag };
 
# Declare some globals
Line 45:
loop {
($phrase, $count, $bag) = get-phrase;
find-anagram Hash.new: %words.race.grep: { .value ⊆ $bag };
}
 
10,333

edits