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

Content deleted Content added
Hout (talk | contribs)
→‎{{header|Python}}: Added a variant selection from the four or more possible meanings of the task definition.
Hout (talk | contribs)
→‎{{header|Haskell}}: Updated output in second variant
Line 277: Line 277:
vowelAndConsonantCounts
vowelAndConsonantCounts
"Forever Fortran 2018 programming language"
"Forever Fortran 2018 programming language"
(vTotal, cTotal) =
putStrLn "Vowel counts:"
both
print v
(show . foldr ((+) . snd) 0)
putStrLn "\nConsonant counts:"
(v, c)
print c</lang>
putStrLn $
<pre>Vowel counts:
vTotal
[('a',4),('e',3),('i',1),('o',3),('u',1)]
<> " instances of "
<> show (length v)
<> " vowels:"
mapM_ print v
putStrLn []
putStrLn $
cTotal
<> " instances of "
<> show (length c)
<> " vowels:"
mapM_ print c


------------------------- GENERIC ------------------------
Consonant counts:

[('F',2),('g',4),('l',1),('m',2),('n',3),('p',1),('r',6),('t',1),('v',1)]</pre>
both :: (a -> b) -> (a, a) -> (b, b)
both = join bimap</lang>
<pre>12 instances of 5 vowels:
('a',4)
('e',3)
('i',1)
('o',3)
('u',1)

21 instances of 9 vowels:
('F',2)
('g',4)
('l',1)
('m',2)
('n',3)
('p',1)
('r',6)
('t',1)
('v',1)</pre>


=={{header|jq}}==
=={{header|jq}}==