Talk:Count how many vowels and consonants occur in a string
Trivial task, but apparently not trivial enough
I was going to recommend this task for deletion as it is incredibly trivial and the operation (identifying whether a character is a vowel or consonant) is covered in a multitude of other tasks. Maybe I am too hasty though, as the task author can't even figure out how to do it correctly. His entry, (the Ring entry) works for the string he used, but will also count [, ], \, _, and ` as consonants. And I don't even program in, or know Ring. Maybe I am guilty of assuming competence that just isn't there. Sigh. --Thundergnat (talk) 13:33, 26 July 2021 (UTC)
- Although his code is certainly wrong, I can't understand why it hasn't given the correct answer for the string he's testing (19 consonants). The only characters it contains which aren't vowels and consonants are space and double-quote and, whilst there are 5 of these, they both have ASCII codes below 65 and so should be excluded from the consonant count. Very strange. --PureFox (talk) 14:03, 26 July 2021 (UTC)
- That problem is/was a misunderstanding of precedence and associativity. An expression such as not x and y is (probably) treated as not (x and y) rather than the (not x) and y as presumably intended. That info is for both PureFox and Calmosoft. I would also like to say that
bool1 = not isvowel(c) bool2 = (ascii(c) > 64 and ascii(c) < 91) bool3 = (ascii(c) > 96 and ascii(c) < 123) if bool1 and (bool2 or bool3)
- would (in any programming language, keyword clashes and precise syntax aside) be much better expressed as
notvowel = not isvowel(c) upper = (ascii(c) > 64 and ascii(c) < 91) lower = (ascii(c) > 96 and ascii(c) < 123) if notvowel and (upper or lower)
- or indeed as a single expression this should also work (untested)
if (not isvowel(c)) and ((ascii(c) > 64 and ascii(c) < 91) or (ascii(c) > 96 and ascii(c) < 123))
- Yes but the problem is that, according to the Ring documentation, 'not x and y' is evaluated as '(not x) and y' because the unary operator 'not' has higher precedence than the binary operator 'and'. It was the first thing I checked when I was trying to understand how he'd managed to arrive at 24 as the answer. What I suspect may have happened here is that he's copy/pasted the results from an earlier version of the code as it seems very unlikely there would be a bug in the language implementation for something as basic as this. --PureFox (talk) 09:14, 27 July 2021 (UTC)
- Doh, I think I might finally have understood it. Here's the original code:
for n = 1 to len(str)
if isvowel(str[n]) = 1
vowel += 1
else not isvowel(str[n]) and ascii(str[n]) > 64 and ascii(str[n]) < 123
cons += 1
- Notice that there's no 'if' after the 'else'. So I think the following expression is simply evaluated and the result discarded. Consequently, if the character isn't a vowel, 'cons' will always be incremented and he'll end up with 24 consonants. --PureFox (talk) 10:05, 27 July 2021 (UTC)
- I'll second the deletion. This task is really hard to do correctly because the rules for when 'y' is a vowel are complicated. The 'y' in "country" used in the examples is unquestionably a vowel. 'y' is a vowel in words like "try" and "system" but not "you" or "yo-yo"). Garbanzo (talk) 01:20, 28 July 2021 (UTC)
I think the task's wording should be expanded a bit (if it is to be kept).
- Check maybe should be changed to Count.
- If a count is desired, then the task should request the showing of the counts.
- An example (or better yet, examples) of what can/should be used so everybody's solution shows the same count(s).
- Maybe it should be specified that only Latin letters are to be counted, and no letters with diacritical marks are to be considered (or maybe they should).
- Should there be a count showing U & u separately? Or show both, a sum of the two cases (upper + lower), and a count that shows the individual cases.
- Is U a different letter than u? It's certainly a different glyph, but is not a different letter. All those other open questions? That is my point completely. Much like nearly every task Calmosoft has ever entered. This is vague, open to interpretation, poorly worded, poorly named and poorly supported. At this point I am all for banning him completely. He causes lots of unnecessary work and conflict; persists in his incompetence, and seems to be unwilling to learn from his mistakes. --Thundergnat (talk) 14:46, 26 July 2021 (UTC)
- Obviously I understand your frustration but ideally there would be a "banned from creating tasks" feature/setting on rc. I mean it's not like there aren't 600+ existing tasks with no Ring entry, and it might be better all round if Calmosoft turned his attention to filling some of them in. It might even be a good idea for everyone to only be allowed to create a new task for every N other additions/updates to tasks they did not create. --Pete Lomax (talk) 03:49, 27 July 2021 (UTC)