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

Added 11l
(→‎{{header|Ring}}: simplified, removed unnecessary library dependency and chance of mis-tabulation of characters after "Z" and before "a")
(Added 11l)
Line 7:
<br><br>
 
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F isvowel(c)
‘ true if c is an English vowel (ignore y) ’
R c C [‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’]
 
F isletter(c)
‘ true if in English standard alphabet ’
R c C ‘a’..‘z’ | c C ‘A’..‘Z’
 
F isconsonant(c)
‘ true if an English consonant ’
R !isvowel(c) & isletter(c)
 
F vccounts(s)
‘ case insensitive vowel counts, total and unique ’
V a = Array(s.lowercase())
V au = Set(a)
R (sum( a.map(c -> Int(isvowel(c)))), sum( a.map(c -> Int(isconsonant(c)))),
sum(au.map(c -> Int(isvowel(c)))), sum(au.map(c -> Int(isconsonant(c)))))
 
V s = ‘Now is the time for all good men to come to the aid of their country.’
V (vcnt, ccnt, vu, cu) = vccounts(s)
print(‘String: ’s"\n Vowels: "vcnt‘ (distinct ’vu")\n Consonants: "ccnt‘ (distinct ’cu‘)’)</lang>
 
{{out}}
<pre>
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|Action!}}==
1,463

edits