Find words with alternating vowels and consonants: Difference between revisions

→‎AppleScript :: Functional: Refactored to generate two listings – aeiou and also aeiouy
m (→‎{{header|AppleScript}}: Minor edit to preamble.)
(→‎AppleScript :: Functional: Refactored to generate two listings – aeiou and also aeiouy)
Line 149:
 
===Functional===
 
Listing 'alternating' words for both '''{a,e,i,o,u}''' and '''{a,e,i,o,u,y}''' interpretations of 'vowel':
<lang applescript>use AppleScript version "2.4"
use framework "Foundation"
Line 155 ⟶ 157:
 
------------ ALTERNATING VOWELS AND CONSONANTS -----------
 
-- alternatingWordQuery :: String -> String
on alternatingWordQuery(regex)
set query to "(9 < self.length) and not (self matches '" & regex & "')"
end alternatingWordQuery
 
 
-- pairRegex :: String -> String
on pairRegex(vowels)
"^.*([" & vowels & "]{2}|[^" & vowels & "]{2}).*$"
end pairRegex
 
 
-- matchingWords :: NSString -> String -> String
on matchingWords(lexicon)
script
on |λ|(vowels)
set query to alternatingWordQuery(pairRegex(vowels))
set matches to filteredLines(query, lexicon)
set intMatches to length of matches
("Assuming " & vowels & " – " & intMatches as text) & ¬
" matches:" & linefeed & linefeed & ¬
inColumns(4, matches)
end |λ|
end script
end matchingWords
 
 
--------------------------- TEST -------------------------
on run
set regex to "^.*([aeiou]{2}|[^aeiou]{2}).*$"
set query to "(9 < self.length) and not (self matches '" & regex & "')"
set fpWordList to scriptFolder() & "unixdict.txt"
if doesFileExist(fpWordList) then
inColumnsintercalate(4linefeed & linefeed, ¬
filteredLinesmap(matchingWords(query, readFile(fpWordList))), ¬
{"aeiou", "aeiouy"}))
else
display dialog "Word list not found atin this script's folder:" & ¬
linefeed & tab & fpWordList
end if
Line 252 ⟶ 283:
result's go(xs)
end chunksOf
 
 
-- concatMap :: (a -> [b]) -> [a] -> [b]
on concatMap(f, xs)
set lng to length of xs
set acc to {}
tell mReturn(f)
repeat with i from 1 to lng
set acc to acc & (|λ|(item i of xs, i, xs))
end repeat
end tell
if {text, string} contains class of xs then
acc as text
else
acc
end if
end concatMap
 
 
Line 273 ⟶ 321:
set widest to maximum(map(my |length|, xs))
unlines({map(lengthmy ofunwords, xs as text) & " matches:" & linefeed} &chunksOf(n, ¬
map(my unwordsjustifyLeft(widest, chunksOf(nspace), ¬xs))))
map(justifyLeft(widest, space), xs))))
end inColumns
 
 
-- intercalate :: String -> [String] -> String
on intercalate(delim, xs)
set {dlm, my text item delimiters} to ¬
{my text item delimiters, delim}
set s to xs as text
set my text item delimiters to dlm
s
end intercalate
 
 
Line 428 ⟶ 485:
end unwords</lang>
{{Out}}
<pre>Assuming aeiou – 67 matches:
 
aboriginal apologetic bimolecular borosilicate
Line 446 ⟶ 503:
savonarola similitude solicitude tananarive
telekinesis teratogenic topologize unilateral
unimodular uninominal verisimilitude</pre>
 
Assuming aeiouy – 101 matches:
 
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 </pre>
 
=={{header|AWK}}==
9,655

edits