Word ladder: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 201:
child to adult: [["This cannot be done."]]
</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>db=DeleteDuplicates[RemoveDiacritics[ToLowerCase[Select[DictionaryLookup[],StringLength/*EqualTo[3]]]]];
sel=Select[Subsets[db,{2}],HammingDistance[#[[1]],#[[2]]]==1&];
g=Graph[db,UndirectedEdge@@@sel];
FindShortestPath[g,"boy","man"]
db=DeleteDuplicates[RemoveDiacritics[ToLowerCase[Select[DictionaryLookup[],StringLength/*EqualTo[4]]]]];
sel=Select[Subsets[db,{2}],HammingDistance[#[[1]],#[[2]]]==1&];
g=Graph[db,UndirectedEdge@@@sel];
FindShortestPath[g,"girl","lady"]
FindShortestPath[g,"john","jane"]
db=DeleteDuplicates[RemoveDiacritics[ToLowerCase[Select[DictionaryLookup[],StringLength/*EqualTo[5]]]]];
sel=Select[Subsets[db,{2}],HammingDistance[#[[1]],#[[2]]]==1&];
g=Graph[db,UndirectedEdge@@@sel];
FindShortestPath[g,"child","adult"]</lang>
{{out}}
<pre>{"boy", "bay", "ban", "man"}
{"girl", "gill", "gall", "gals", "gads", "lads", "lady"}
{"john", "join", "jain", "main", "mann", "mane", "jane"}
{}</pre>
=={{header|Nim}}==
|