your logic is wrong, comparing the sums of ascii codes will lead to false positives, e.g. your code returns true for "ac", "bb".
Other issues:
you cast const away in your loop to convert the strings to uppercase --> don't do that; not only is it bad practice but it will crash when the strings are immutable
this same loop also assumes that the strings are the same length and that they have lowercase letters at the same indices... you should iterate on them separately, after making a copy first
Oy. nevermind, I was looking at your solution thinking it was your working draft but it apparently works and I'm obviously wrong about things. My apologies
You're only changing even in the event that the first two array elements are the same. I'm betting those will be the tests that do pass. Otherwise even == 0 so when you check arr[i] against it inside the loop, it does nothing good for you.
It always helps to mention your language. And yes, users who completed the kata in the same langiage can see your most recently attempted code.
Again, you sohuld try and run your solution locally, in your IDE, and call it twice in one test run. There's more than one problem with it currently, but the main issue is the while loop which is not really necessary, and causes the problem you see.
Another issue is returning a statically allocated buffer, what is almost always wrong. This kata wants you to return a malloced, freeable buffer.
your logic is wrong, comparing the sums of ascii codes will lead to false positives, e.g. your code returns
true
for"ac", "bb"
.Other issues:
const
away in your loop to convert the strings to uppercase --> don't do that; not only is it bad practice but it will crash when the strings are immutablenot sure for C but the logic is: check if your summ divides with no remainder first, if yes then just return summ/n C:
No worries :) be aware of the difference between a null string and and an empty one.
What happens in your solution if the string is empty?
op solved the kata
OP solved it, closing
me to
For the 1st sample test, your code returns
true
. However, the inputincludes an underscore, so your code should have returned
false
.Oy. nevermind, I was looking at your solution thinking it was your working draft but it apparently works and I'm obviously wrong about things. My apologies
You're only changing
even
in the event that the first two array elements are the same. I'm betting those will be the tests that do pass. Otherwiseeven == 0
so when you checkarr[i]
against it inside the loop, it does nothing good for you.have you figure it out? It was quite challenging and satisfying to complete this task.
added better messages
It always helps to mention your language. And yes, users who completed the kata in the same langiage can see your most recently attempted code.
Again, you sohuld try and run your solution locally, in your IDE, and call it twice in one test run. There's more than one problem with it currently, but the main issue is the
while
loop which is not really necessary, and causes the problem you see.Another issue is returning a statically allocated buffer, what is almost always wrong. This kata wants you to return a malloced, freeable buffer.
Loading more items...