Count how many vowels and consonants occur in a string: Difference between revisions

Content deleted Content added
Loren (talk | contribs)
Added X86 Assembly example.
Wherrera (talk | contribs)
julia example
Line 122: Line 122:
contains (distinct 5 vowels and 13 consonants.
contains (distinct 5 vowels and 13 consonants.
</pre>
</pre>

=={{header|Julia}}==
<lang julia>isvowel(c) = c in ['a', 'e', 'i', 'o', 'u', 'A', 'E', "I", 'O', 'U']
isletter(c) = 'a' <= c <= 'z' || 'A' <= c <= 'Z'
isconsonant(c) = !isvowel(c) && isletter(c)

function vccounts(s)
a = collect(lowercase(s))
au = unique(a)
count(isvowel, a), count(isconsonant, a), count(isvowel, au), count(isconsonant, au)
end

function testvccount()
teststrings = [
"Forever Julia programming language",
"Now is the time for all good men to come to the aid of their country."]
for s in teststrings
vcnt, ccnt, vu, cu = vccounts(s)
println("String: $s\n Vowels: $vcnt (distinct $vu)\n Consonants: $ccnt (distinct $cu)\n")
end
end

testvccount()
</lang>{{out}}
<pre>
String: Forever Julia programming language
Vowels: 13 (distinct 5)
Consonants: 18 (distinct 9)

String: Now is the time for all good men to come to the aid of their country.
Vowels: 22 (distinct 5)
Consonants: 31 (distinct 13)
</pre>



=={{header|Phix}}==
=={{header|Phix}}==