Find words with alternating vowels and consonants: Difference between revisions

Content added Content deleted
m (→‎{{header|AppleScript}}: Minor edit to preamble.)
(→‎AppleScript :: Functional: Refactored to generate two listings – aeiou and also aeiouy)
Line 149: Line 149:


===Functional===
===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"
<lang applescript>use AppleScript version "2.4"
use framework "Foundation"
use framework "Foundation"
Line 155: Line 157:


------------ ALTERNATING VOWELS AND CONSONANTS -----------
------------ ALTERNATING VOWELS AND CONSONANTS -----------

-- alternatingWordQuery :: String -> String
on alternatingWordQuery(regex)
"(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
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"
set fpWordList to scriptFolder() & "unixdict.txt"
if doesFileExist(fpWordList) then
if doesFileExist(fpWordList) then
inColumns(4, ¬
intercalate(linefeed & linefeed, ¬
filteredLines(query, readFile(fpWordList)))
map(matchingWords(readFile(fpWordList)), ¬
{"aeiou", "aeiouy"}))
else
else
display dialog "Word list not found at:" & ¬
display dialog "Word list not found in this script's folder:" & ¬
linefeed & tab & fpWordList
linefeed & tab & fpWordList
end if
end if
Line 252: Line 283:
result's go(xs)
result's go(xs)
end chunksOf
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: Line 321:
set widest to maximum(map(my |length|, xs))
set widest to maximum(map(my |length|, xs))
unlines({(length of xs as text) & " matches:" & linefeed} & ¬
unlines(map(my unwords, chunksOf(n, ¬
map(my unwords, chunksOf(n, ¬
map(justifyLeft(widest, space), xs))))
map(justifyLeft(widest, space), xs))))
end inColumns
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: Line 485:
end unwords</lang>
end unwords</lang>
{{Out}}
{{Out}}
<pre>67 matches:
<pre>Assuming aeiou – 67 matches:


aboriginal apologetic bimolecular borosilicate
aboriginal apologetic bimolecular borosilicate
Line 446: Line 503:
savonarola similitude solicitude tananarive
savonarola similitude solicitude tananarive
telekinesis teratogenic topologize unilateral
telekinesis teratogenic topologize unilateral
unimodular uninominal verisimilitude</pre>
unimodular uninominal verisimilitude

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}}==
=={{header|AWK}}==