Anagrams: Difference between revisions
Content deleted Content added
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:
use scripting additions
on largestAnagramGroups(listOfWords)
script o
property wordList :
property doctoredWords : {}
property longestRanges : {}
Line 531:
end script
-- The words in "unixdict.txt" are in alphabetical order, one per line.▼
-- Some contain punctuation characters, so they're best extracted as 'paragraphs' rather than as 'words'.▼
set wordFile to ((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as «class furl»▼
set o's wordList to paragraphs of (read wordFile as «class utf8»)▼
ignoring case
-- Build another list containing doctored versions of the
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
Line 542 ⟶ 538:
set theseChars to thisWord's characters
-- A straight ascending in-place sort here.
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
end repeat
Line 576 ⟶ 572:
-- 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
repeat with thisRange in o's longestRanges
set {i, j} to thisRange
Line 592 ⟶ 588:
return o's output
end largestAnagramGroups
-- The closing values of AppleScript 'run handler' variables not explicity declared local are
-- saved back to the script file afterwards — and "unixdict.txt" contains 25,104 words!
local wordFile, wordList
▲
▲
return largestAnagramGroups(wordList)</lang>
{{output}}
|