Anagrams: Difference between revisions
Content added Content deleted
m (added related tasks.) |
m (→{{header|AppleScript}}: Handler modified to take an array of words as a parameter instead of specifically reading "unixdict.txt".) |
||
Line 523: | Line 523: | ||
use scripting additions |
use scripting additions |
||
on largestAnagramGroups(listOfWords) |
|||
on anagramsTask() |
|||
script o |
script o |
||
property wordList : |
property wordList : listOfWords |
||
property doctoredWords : {} |
property doctoredWords : {} |
||
property longestRanges : {} |
property longestRanges : {} |
||
Line 531: | Line 531: | ||
end script |
end script |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
ignoring case |
ignoring case |
||
-- Build another list containing doctored versions of the |
-- Build another list containing doctored versions of the input words with their characters lexically sorted. |
||
set astid to AppleScript's text item delimiters |
set astid to AppleScript's text item delimiters |
||
set AppleScript's text item delimiters to "" |
set AppleScript's text item delimiters to "" |
||
Line 542: | Line 538: | ||
set theseChars to thisWord's characters |
set theseChars to thisWord's characters |
||
-- A straight ascending in-place sort here. |
-- A straight ascending in-place sort here. |
||
tell sorter to sort(theseChars, 1, -1, {}) -- Params: (list, start index, end index, customisation spec.). |
tell sorter to sort(theseChars, 1, -1, {}) -- Params: (list, start index, end index, customisation spec.). |
||
set end of o's doctoredWords to theseChars as text |
set end of o's doctoredWords to theseChars as text |
||
end repeat |
end repeat |
||
Line 576: | Line 572: | ||
-- Get the group(s) of words occupying the same range(s) in the original-word list. |
-- Get the group(s) of words occupying the same range(s) in the original-word list. |
||
-- The stable parallel sort above will have kept each group's words in |
-- The stable parallel sort above will have kept each group's words in the same order with respect to each other. |
||
repeat with thisRange in o's longestRanges |
repeat with thisRange in o's longestRanges |
||
set {i, j} to thisRange |
set {i, j} to thisRange |
||
Line 592: | Line 588: | ||
return o's output |
return o's output |
||
end largestAnagramGroups |
|||
end anagramsTask |
|||
-- The closing values of AppleScript 'run handler' variables not explicity declared local are |
|||
anagramsTask()</lang> |
|||
-- saved back to the script file afterwards — and "unixdict.txt" contains 25,104 words! |
|||
local wordFile, wordList |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return largestAnagramGroups(wordList)</lang> |
|||
{{output}} |
{{output}} |