Anagram generator: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 34:
Implementation:
 
<langsyntaxhighlight lang=J>anagen=: {{
seed=. (tolower y)([-.-.)a.{~97+i.26
letters=. ~.seed
Line 55:
end.
EMPTY
}}</langsyntaxhighlight>
 
Conceptually, we're working with a graph here -- given a seed word, we have sequence of letters and a count of each of those letters which we must supply. Given a list of words whose letters do not exceed that count, we extend that list with an additional word, discarding word sequences which go over the letter count. We would repeat as necessary until we satisfy the needed letter counts. Also, we inspect the "final result" and remove our seed word or phrase from it (if it was present -- and if that would have been our only result we would extend our under budget word sequences until they satisfy our letter counts). It seems like two words is usually sufficient here.
Line 65:
Examples:
 
<langsyntaxhighlight lang=J> 'unixdict.txt' anagen 'Rosettacode'
cetera stood
coat oersted
Line 135:
piazza trim type
piety pizza tram
pizza pyrite tam</langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang=ruby>const unixwords = split(read("unixdict.txt", String) |> lowercase, r"\s+")
 
function findphrases(anastring::AbstractString, choices, sizelong = 4, n_shortpermitted = 1)
Line 175:
foreach(println, findphrases(s, unixwords, 4, 0) |> unique |> sort!)
end
</langsyntaxhighlight>{{out}}
<pre>
From 'Rosetta code':
Line 210:
=={{header|Phix}}==
Couldn't really think of a better way than just building a dirty great filter list to get rid of the less interesting answers....
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">bo_ring</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"al"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"alex"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"am"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"an"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"and"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"anent"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ann"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ant"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ar"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ares"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"art"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"at"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ax"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"axle"</span><span style="color: #0000FF;">,</span>
Line 266:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"Rosetta"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"PureFox"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"PeteLomax"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Wherrera"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Thundergnat"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">test</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 318:
Using the unixdict.txt word file by default.
 
<langsyntaxhighlight 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;
Line 357:
}
}
}</langsyntaxhighlight>
{{out|Truncated to only show the best few as subjectively determined by me}}
''Punctuation, capitalization and (in some cases) word order manually massaged.''
Line 382:
 
Alternatives formed by simply changing the order of the two words have been suppressed.
<langsyntaxhighlight lang=ecmascript>import "io" for File
import "./str" for Str, Char
import "./perm" for Comb
Line 445:
System.print("\n%(tests[i]):")
anagramGenerator.call(tests[i])
}</langsyntaxhighlight>
 
{{out}}
10,327

edits