Anagrams: Difference between revisions
m
→{{header|AppleScript}}: New sort handler URL, tidy-up.
m (→{{header|AppleScript}}: New sort handler URL, tidy-up.) |
|||
Line 916:
=={{header|AppleScript}}==
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later
use sorter : script ¬
"Custom Iterative Ternary Merge Sort" -- <www.macscripter.net/t/timsort-and-nigsort/71383/3>
use scripting additions
on join(lst, delim)
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
on largestAnagramGroups(listOfWords)
script o
property wordList : listOfWords
property
property
property
if (groupSize < largestGroupSize) then -- Most likely.
else if (groupSize = largestGroupSize) then -- Next most likely.
end if▼
on isGreater(a, b)
end script
set wordCount to (count o's wordList)
ignoring case
--
set
set
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
--
▲ set AppleScript's text item delimiters to astid
--
▲ tell sorter to sort(o's doctoredWords, 1, -1, {slave:{o's wordList}})
▲ -- Find the range(s) of the longest run(s) of equal texts in the doctored-word list.
set longestRunLength to 1▼
set i to 1
set currentText to beginning of o's
repeat with j from 2 to
set thisText to
if (thisText is not currentText) then
▲ set o's longestRanges to {{i, j - 1}}
▲ set longestRunLength to thisRunLength
▲ end if
set currentText to thisText
set i to j
end if
end repeat
▲ set o's longestRanges to {{i, j}}
▲ set end of o's longestRanges to {i, j}
▲ end if
--
repeat with thisRange in o's
set {i, j} to thisRange
set thisGroup to o's wordList's items i thru j
▲ tell sorter to sort(
end repeat
-- As a final flourish, sort the
tell sorter to sort(output, 1, -1, {comparer:o})
▲ on isGreater(a, b)
▲ return (a's beginning > b's beginning)
▲ end isGreater
▲ end script
▲ tell sorter to sort(o's output, 1, -1, {comparer:byFirstItem})
end ignoring
return
end largestAnagramGroups
local wordFile, wordList
set wordFile to ((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as «class furl»▼
▲set wordFile to ((path to desktop as text) & "unixdict.txt") as «class furl»
set wordList to paragraphs of (read wordFile as «class utf8»)
return largestAnagramGroups(wordList)</syntaxhighlight>
Line 1,001:
{{output}}
<syntaxhighlight lang="applescript">{{"abel", "able", "bale", "bela", "elba"}, {"alger", "glare", "lager", "large", "regal"}, {"angel", "angle", "galen", "glean", "lange"}, {"caret", "carte", "cater", "crate", "trace"}, {"elan", "lane", "lean", "lena", "neal"}, {"evil", "levi", "live", "veil", "vile"}}</syntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
|