I am trying to count vowel groups in a sentence.
My first attempt was to use list comprehension to reduce the sentence to a list of boolean values for each Char, depending on if it is a vowel or not. However, I’m not sure how to count the groups of consecutive “True” values in the list. Is there any trick to do this?
It was located in my textbook in a chapter dealing with lists and list comprehension, so I feel it has something to do with that.
Since I don’t know whether it’s a homework, I’m going to give you hints:
In Data.List:
You can write your own:
So you should be able to get the list you mention, with
Bools, and now you want to count the groups that are “all True”.Any of these two fellows should prove useful, since both can reduce a list of all-equal boolean values into a single value equal to them.
(EDIT: As mentioned in a comment, I’m overworking here, you just need to take the
headof each “group”. In fact, you can also guess the number of vowel groups just by looking at whether the first group is a vowel/consonant, and by counting the number of groups, since for sure there is an alternation vowel/consonant!)And now, you just need to count the
Trues in this final list, since eachTruerepresents a group of vowels!You should be able to do the plumbing by yourself with these indications!