Find words with alternating vowels and consonants: Difference between revisions

m
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 1,454:
telekinesis teratogenic topologize unilateral unimodular uninominal verisimilitude
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn LoadDictionaryIntoMemory
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef dictStr = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
AppSetProperty( @"dictionary", dictStr )
end fn
 
local fn HasAlternatingVowelsAndConsonants( wordStr as CFStringRef ) as BOOL
NSUInteger i, count = len( wordStr )
CFCharacterSetRef vowels = fn CharacterSetWithCharactersInString( @"aeiouAEIOU" )
CFMutableCharacterSetRef consonants = fn MutableCharacterSetLetterSet
MutableCharacterSetRemoveCharactersInString( consonants, @"aeiouAEIOU" )
CFCharacterSetRef vowelsInvertedSet = fn CharacterSetInvertedSet( vowels )
BOOL isVowelExpected = fn CharacterSetCharacterIsMember( vowelsInvertedSet, fn StringCharacterAtIndex( wordStr, 0 ) )
for i = 1 to count - 1
unichar chr = fn StringCharacterAtIndex( wordStr, i )
BOOL isVowel = fn CharacterSetCharacterIsMember( vowels, chr )
if ( (isVowel && isVowelExpected) || (!isVowel && !isVowelExpected) )
isVowelExpected = !isVowelExpected
else
exit fn = NO
end if
next
end fn = YES
 
local fn FindQualifiers
CFStringRef testWord
NSUInteger i = 1
CFStringRef dictStr = fn AppProperty( @"dictionary" )
CFArrayRef dictArray = fn StringComponentsSeparatedByString( dictStr, @"\n" )
CFMutableStringRef mutStr = fn MutableStringNew
for testWord in dictArray
if ( len( testWord ) > 9 )
if ( fn HasAlternatingVowelsAndConsonants( testWord ) )
MutableStringAppendString( mutStr, fn StringWithFormat( @"%3d. %@\n", i, testWord ) )
i++
end if
end if
next
NSLog( @"%@", mutStr )
end fn
 
fn LoadDictionaryIntoMemory
fn FindQualifiers
 
HandleEvents
</syntaxhighlight>
{{out}}
<pre style="height:15em">
1. aboriginal
2. apologetic
3. bimolecular
4. borosilicate
5. calorimeter
6. capacitate
7. capacitive
8. capitoline
9. capitulate
10. caricature
11. colatitude
12. coloratura
13. colorimeter
14. debilitate
15. decelerate
16. decolonize
17. definitive
18. degenerate
19. deliberate
20. demodulate
21. denominate
22. denotative
23. deregulate
24. desiderata
25. desideratum
26. dilapidate
27. diminutive
28. epigenetic
29. facilitate
30. hemosiderin
31. heretofore
32. hexadecimal
33. homogenate
34. inoperative
35. judicature
36. latitudinal
37. legitimate
38. lepidolite
39. literature
40. locomotive
41. manipulate
42. metabolite
43. nicotinamide
44. oratorical
45. paragonite
46. pejorative
47. peridotite
48. peripatetic
49. polarimeter
50. recitative
51. recuperate
52. rehabilitate
53. rejuvenate
54. remunerate
55. repetitive
56. reticulate
57. savonarola
58. similitude
59. solicitude
60. tananarive
61. telekinesis
62. teratogenic
63. topologize
64. unilateral
65. unimodular
66. uninominal
67. verisimilitude
</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
Line 2,169 ⟶ 2,293:
<pre>{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}</pre>
 
=={{header|MiniScript}}==
This implementation is for use with the [http://miniscript.org/MiniMicro Mini Micro] version of MiniScript. The command-line version does not include a HTTP library. The script can be modified to use the file class to read a local copy of the word list.
<syntaxhighlight lang="miniscript">
isVowel = function(c)
return "aeiou".indexOf(c) != null
end function
 
isAlternating = function(word)
compVowelState= isVowel(word[0])
for i in range(1, word.len - 1)
if isVowel(word[i]) == compVowelState then return false
compVowelState = not compVowelState
end for
return true
end function
 
wordList = http.get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").split(char(10))
results = []
 
for word in wordList
if word.len >9 and isAlternating(word) then results.push(word)
end for
c = 0
 
for word in results
word = (word + " " * 5)[:15] // padded for printing
print word, ""
c = c + 1
if c % 4 == 0 then print
end for
</syntaxhighlight>
 
{{out}}
<pre>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
</pre>
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strutils
Line 3,300 ⟶ 3,475:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./fmt" for Fmt
 
var isVowel = Fn.new { |c| "aeiou".contains(c) }
729

edits