Jump to content

Anadromes: Difference between revisions

m
→‎{{header|AppleScript}}: Nicer logic in the second repeat.
(Realize in F#)
m (→‎{{header|AppleScript}}: Nicer logic in the second repeat.)
Line 159:
set wordArray to (wordArray's filteredArrayUsingPredicate:(filter))
-- Derive a list of the reversed remaining words. This is what takes most of the time.
script o
property wordList : wordArray as list
Line 166:
set AppleScript's text item delimiters to ""
repeat with i from 1 to (count o's wordList)
set item i of o's wordList's to (item i ofto (o's wordList)'s item i's characters's reverse) as text
end repeat
Line 177:
set o's wordList to (wordSet's allObjects()'s sortedArrayUsingSelector:("localizedStandardCompare:")) as list
-- Construct the output line by line, omitting palindromes and already matched word pairs that have been covered already.
set output to {}
repeat with thisWordi infrom 1 to (count o's wordList)
set reversedWordthisWord to thisWordo's characterswordList's reverse asitem texti
set o's wordList's item i to missing value
if not ((thisWord's contents is reversedWord) or (output contains {reversedWord & " <--> " & thisWord})) then
set end of outputreversedWord to (thisWord's &characters's "reverse) <-->as " & reversedWordtext
if (reversedWord is in o's wordList) then set output's end to thisWord & " <--> " & reversedWord
end if
end repeat
set AppleScript's text item delimiters to linefeed
557

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.