Find words with alternating vowels and consonants: Difference between revisions

Added AppleScript.
m (→‎{{header|Haskell}}: (slight disaggregation))
(Added AppleScript.)
Line 85:
67 words of alternating vowels and consonants found
</pre>
 
=={{header|AppleScript}}==
 
<lang applescript>(*
With AppleScript's text item delimiters set to all the vowels, the 'text items' of a word with alternating
vowels and consonants are single-character strings (the consonants), with the possibility of an empty
string at the beginning and/or end representing a leading and/or trailing vowel.
*)
 
on findWordsWithAlternatingVowelsAndConsonants from theText given minLength:minLength, yAsVowel:yAsVowel
script o
property wordList : theText's words
property output : {}
end script
set astid to AppleScript's text item delimiters
if (yAsVowel) then
set AppleScript's text item delimiters to {"a", "e", "i", "o", "u", "y"}
else
set AppleScript's text item delimiters to {"a", "e", "i", "o", "u"}
end if
ignoring case and diacriticals
repeat with thisWord in o's wordList
set thisWord to thisWord's contents
if ((count thisWord) ≥ minLength) then
set textItems to thisWord's text items
set a to 1
if ((count beginning of textItems) is 0) then set a to 2
set b to (count textItems)
if ((count end of textItems) is 0) then set b to b - 1
repeat with i from a to b
set alternating to ((count item i of textItems) is 1)
if (not alternating) then exit repeat
end repeat
if (alternating) then set end of o's output to thisWord
end if
end repeat
end ignoring
set AppleScript's text item delimiters to astid
return o's output
end findWordsWithAlternatingVowelsAndConsonants
 
-- Task code:
local theText
set theText to (read file ((path to desktop as text) & "unixdict.txt") as «class utf8»)
findWordsWithAlternatingVowelsAndConsonants from theText without yAsVowel given minLength:10</lang>
 
{{output}}
<lang applescript>{"aboriginal", "apologetic", "bimolecular", "borosilicate", "calorimeter", "capacitate", "capacitive", "capitoline", "capitulate", "caricature", "colatitude", "coloratura", "colorimeter", "debilitate", "decelerate", "decolonize", "definitive", "degenerate", "deliberate", "demodulate", "denominate", "denotative", "deregulate", "desiderata", "desideratum", "dilapidate", "diminutive", "epigenetic", "facilitate", "hemosiderin", "heretofore", "hexadecimal", "homogenate", "inoperative", "judicature", "latitudinal", "legitimate", "lepidolite", "literature", "locomotive", "manipulate", "metabolite", "nicotinamide", "oratorical", "paragonite", "pejorative", "peridotite", "peripatetic", "polarimeter", "recitative", "recuperate", "rehabilitate", "rejuvenate", "remunerate", "repetitive", "reticulate", "savonarola", "similitude", "solicitude", "tananarive", "telekinesis", "teratogenic", "topologize", "unilateral", "unimodular", "uninominal", "verisimilitude"}</lang>
 
Or if you want to treat "y" as a vowel:
 
<lang applescript>-- Task code:
local theText
set theText to (read file ((path to desktop as text) & "unixdict.txt") as «class utf8»)
findWordsWithAlternatingVowelsAndConsonants from theText with yAsVowel given minLength:10</lang>
 
{{output}}
<lang applescript>{"aboriginal", "apologetic", "bimolecular", "borosilicate", "calorimeter", "capacitate", "capacitive", "capitoline", "capitulate", "caricature", "cohomology", "colatitude", "coloratura", "colorimeter", "debilitate", "decelerate", "decolonize", "definitive", "degeneracy", "degenerate", "dehumidify", "deliberate", "demodulate", "denominate", "denotative", "depositary", "depository", "deregulate", "deregulatory", "derogatory", "desiderata", "desideratum", "dicotyledon", "dilapidate", "diminutive", "epigenetic", "facilitate", "generosity", "hemosiderin", "hereditary", "heretofore", "heterodyne", "hexadecimal", "homogenate", "hypotenuse", "inoperative", "judicatory", "judicature", "laboratory", "latitudinal", "latitudinary", "legitimacy", "legitimate", "lepidolite", "literature", "locomotive", "locomotory", "luminosity", "manipulate", "metabolite", "mineralogy", "monocotyledon", "musicology", "nicotinamide", "numerology", "oratorical", "paragonite", "paramilitary", "pejorative", "peridotite", "peripatetic", "polarimeter", "polymerase", "pyrimidine", "pyroxenite", "recitative", "recuperate", "regulatory", "rehabilitate", "rejuvenate", "remunerate", "repetitive", "repository", "reticulate", "revelatory", "savonarola", "similitude", "solicitude", "solidarity", "tananarive", "telekinesis", "teratogenic", "teratology", "topologize", "toxicology", "unilateral", "unimodular", "uninominal", "verisimilitude", "veterinary", "vocabulary"}</lang>
 
=={{header|AWK}}==
557

edits