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

Content added Content deleted
Line 25: Line 25:


::: Yes but the problem is that, according to the [https://ring-lang.sourceforge.io/doc1.14/operators.html 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. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 09:14, 27 July 2021 (UTC)
::: Yes but the problem is that, according to the [https://ring-lang.sourceforge.io/doc1.14/operators.html 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. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 09:14, 27 July 2021 (UTC)

:::: Doh, I think I might finally have understood it. Here's the original code:
::::<lang ring>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
ok
next</lang>
:::: 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. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 10:05, 27 July 2021 (UTC)


== task wording ==
== task wording ==