8 kyu
How good are you really?
57,937 of 167,435Jotha
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
There is no need to post solutions in discourse. Your solution is already posted to the solutions page when you hit the submit button in the code editor. A suggestion is a comment intended to improve the kata in some way, it is not an appropriate tag to use when posting spoilers.
.
.
The request ask you to do something, and mark it as important.
After you do that, it says
Oh, You don't really need to do that.
Seriously?
the php code doesn't have to include your own points in the array of class points to pass the test, that is a mistake in the task.
see here
They need better test cases because the top code in solutions with almost 4000 similar variations didnt even follow the instructions to include your own scores as well.
see here, tl;dr mathematically speaking, your own scores included to the total doesn't matter to the result
It's not possible to write test cases for that because it doesn't make a difference. They should remove it from the instructions instead.
The test cases need work considering many of the solutions that do not factor in your points pass.
see here
It's not a problem with the test cases, they should remove it from the instructions because it doesn't make a difference.
This comment has been hidden.
I don't append your point into class points but the code run without error and i pass this kata
added to the tests, thanks :)
This comment has been hidden.
Note that precedence of
*
and/
are greater than+
and-
This comment has been hidden.
what to do if classpoints==yourpoints? it is issue
==
does not mean "better".oh thanks sorry
you would have to apply >= # Equal to your greater than
Rust translate
merged with minor edits for compability with 1.66
Instructions explicitly say not to forget your points when calculating the class average, but all tests are passed even if you do indeed ignore your points when calculating class average. The most popular solution to this kata doesn't solve it correctly, it calculates the class average incorrectly but still passes the tests.
See https://www.codewars.com/kata/5601409514fc93442500010b/discuss/#6508d1141143df1f2e4d7458.
In the instructions it states to return True, or False (not boolean true or false, nor does it use quotes to indicate a string). After a test it's easy enough to understand it wants a boolean return. Just a note.
that's probably because they are spelled that way in Python; but since most other languages spell them in lowercase i changed it accordingly
Thanks for letting me know how Python labels booleans. I didn't know that.
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in discourse.
This comment has been hidden.
Please don't post solutions in the discourse. If you want to discuss solutions, use the "Solutions" page. See https://docs.codewars.com/training/troubleshooting#post-discourse.
This comment has been hidden.
The test case is correct, not a kata issue. Please don't raise issues so lightly. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
You're missing the point about average there.
The average isn't 100 there, that's the score of a single student.
This comment has been hidden.
OP's attempted language is most probably C++.
Mathematically it makes no difference whether you include your points or not (which I believe is the issue you're pointing out?). Please see my comment here, or correct me if I'm reading you wrong.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Honestly, my head is about to explode. I'm so bad at logic xdd! Thanks you very much, really clever.
This comment has been hidden.
Nothing is preimported, why do you need Linq? You can sum numbers without it and if you want to use it, simply import it. Also, mark your post as having spoiler content next time.
Sorry, but i got disappointed, because i saw earlier useful pre-iports in other challenges, and also the 'test version' of this challenge has the Linq, so i thought that it could be better if it was pre-imported as i said that's all ;)
This comment has been hidden.
No it does not. Why would you think so?
I used a print statement like so
printf("%d\n", class_size)
and it returned -1.
did you put it at the top of your solution, as a very first line in your function? can you show your function together with the
printf
?1Ohhhhh ! Now I understand, I iterated on class_size-- so at the end it would be -1. Thanks for helping me understand my mistake.
Closing the issue as invalid.
This comment has been hidden.
Mathematically it makes no difference whether you include your points or not. Please see my comment here.
.
The description indicates that you should include YourPoints in the ClassPoints List to calculate the average. However, a lot of answers do not include this step, which should be considered incorrect, but they still pass all the tests. There should at least have a test to invalidate this or this part of the question should be removed since in this cenario it have no meaning.
This comment has been hidden.
you are totally correct with what you explained, but why would you say it has to be included, if you don't check for the fact if it is included or not?
This comment has been hidden.
This comment has been hidden.
Please use code formatting when posting blocks of code.
This comment has been hidden.
Sorry for the ugly formatting I tried to fix it (cause it was even worse a second ago) but I don't know to format for code.
It's explained in the link I posted, is it not clear enough?
I made that comment maybe a tad hastily before I even read your reply, hobovsky. Thanks for clarifying that though, I'll bear that in mind for future comments.
can any one suggest the ternary solution to this!
I wrote the function in JS and it works, but the test keeps failing. Something is wrong with this kata.
Just look at the error message you're getting.
You are returning a string, and this kata expects a Boolean output.
Thank you! That's right! I've modified the code.
This comment has been hidden.
there was only one of them. fixed + added better assertion messages
I keep on failing FixedTest([100, 90],11). Anybody have any idea what I'm doing wrong here?
I am working in C# and I have got a functional solution based on an array and some if statements, but I keep failing that one test there and I'm racking my brains trying to work out why.
why are you replacing the given input with your own data inside the function?
the function should use the given input
Just to test my own solution out, really.
Nonetheless, that would make sense. I apologise, I am a bit new here.
Actually, where is the given input?
Do you mean the inputs listed within the sample tests or something different?
This comment has been hidden.
This comment has been hidden.
that's (possibly) because you were trying to re-declare the variables. once already defined with a type, you cannot do that again.
btw, you don't need the spoiler flag unless your comment reveals code solution methods
The description is wrong, if you add your scrore the tests will fail
This is incorrect.
Think about it; if you have a set of numbers and you add one extra, the mean of the new set will be:
old_mean + ((new_num - old_mean)/(old_set.length + 1))
It cannot become equal the new number unless the new number is equal to the old mean, in which case the mean will not change. If the mean was below the new number it will remain below, if equal it will remain equal, and if above it will remain above.
The truth value of this function therefore cannot change based on the addition (or not) of your own score. You have a logical error in your code if this is happening.
Scala translation
LGTM, Approved!
Уже вторая задача с проблемами с тестами, а именно когда нужно програть через reduce или for. язык JavaScript, уверен, что мое решение корректное, но автотесты не пропускают)
Hi, when I use 'ClassPoints.Sum()' in C# version 10 I get an error stating that an array of int does not have a Sum method. In Visual Studio 2022 the code works, though. Is that a known difference?
You need to include the relevant imports.
Closing as this is not a kata issue.
This comment has been hidden.
Yeah for c# the top-voted solution doesn't appear to add MyPoints to the average. I'm new so I'm not sure if there is a mistake here or if I'm missing something.
Mathematically it makes no difference whether you include your points or not. Please see my comment here.
I don't know if the description changes per language used but it says the following:
which would imply that I need to return string True or False, since the keywords in JS are lowercase.
Could that be a quick fix?
This comment has been hidden.
That's because you have a bug in your solution. What is expected answer for input:
classPoints=[2, 3], yourPoints=5
? What does your solution return?A bug in your solution is not a kata issue;
(2+3+5)/3 < 5 shouldn't this return true? and sorry didn't know that issue tag meant that the issue is with the kata itself.
(2+3+5)/3 < 5
should returntrue
, but it is not what you have in your code.Can you check locally what your solution returns for this input?
i checked locally and the problem is the absence of the parentheses here
(ClassPoints.Length+1)
this way it works fine. thanks for the reply.
The description states:
In languages where array size is fixed (Java, C, NASM, C# ...) this suggestion cannot be followed, unless an extra empty element is added to the array, which would be very awkward and invalidate existing solutions. This suggestion should either be removed, or put inside an
if:
block.I think that the point of the note is good (i.e. to stress the fact that user's grade is not included in the pool of class' grades), just the wording is unfortunate. I'd say that the note is applicable to every language, but its wording is not abstract enough.
the issue is only with the wording of the second sentence that i quoted, not the first, but I cannot edit it anymore
'add your point to the given array' really sounds like you are encouraged to do
grades.push/append(myGrade)
, which is not possible with static arraysbetter than what?
I believe the answer to your question is: 'If your score is better than the average score of the class.'
Good katas to introduce yourself with the reduce practice
Not a kata suggestion.
The description states that you may add your own point to the list of points, but that will fail the tests.
No, I did that and it passed all tests. I'm a bit disappointed that there wasn't a test that invalidated the answers which didn't add your points.
Sorry, forgot to mention that I was talking about the C translation which won't allow it.
this concerns all languages where arrays' length is static, re-raising
This comment has been hidden.
Hi - I think you are solving a slightly different exercise: the description asks:
"You want to know if you're better than the average student in your class."
whereas currently you are calculating better than the best student.
(also small comment: your answer will always return
False
since, if the max of an array isM
then there will never be another element in the array that is greater thanM
)PHP 8.0. "class MyTestCases extends TestCase { " gives error - "Test class name must end with 'Test' for test runs". Changing class name for MyTest solves the case.
Fixed.
This comment has been hidden.
Please don't post solutions in Discourse.
I AM AWESOME
This one is tricky but interesting . It will help to clear the concept of loop and function.
got error in test
'betterThanAverage([100, 40, 34, 57, 29, 72, 57, 88], 75) should return True' said in console.
Why 75 > 100? Lol
What's the average there? Is it greater or smaller than 75?
As you can see - array contains 100 and my number is 75. Console error said that this array need to return True. But 75 is not > 100. and my func dont pass the test just bcs of this test array...
The average value is less than 75, do you know what average means right? If not, read this: https://en.wikipedia.org/wiki/Average
oh, my bad, i miss that :) i just compared each obj with mine... Thanks man
C: initial code should include the header
stdbool.h
and return type should bebool
.done + added
const
qualifier to the array and better failure messagesFor C - lang You should return 1 or 0, not True or False to pass all the tests.
Raised as an issue.
If anyone else is getting Error Code 422, In test Cases, change the class name from:
To:
Which language? This should be fixed in the kata directly.
That looks like PHP.
How are you supposed to ask for help in codewars? I see they hide comments with possible solutions. I believe I have a working solution, but a test is still failing.
Read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Don't post solutions in discourse.
please delete THIS comment
this is discourse, not a place to post your solution
cool kata BUT the instructions call a bool-function, but we have int-function so to passed the test you need to return 1 or 0
What language?
If you mean C, then it's fixed. Now your solution can return any truthy value to pass.
If you mean some other language, please tell which one.
Sorry, but for C it's not fixed, I got error returning True or False, but when i've changed to 1 and 0, I passed all the tests.
One of the most confusing questions of the Fundamental kata section. The Note section about including yourself takes some puzzling to understand – and then it's not even required.
This comment has been hidden.
This is not a kata issue (= a bug in the kata). Please use markdown tags to format your code or it's not usable. Refer to the documentation about this and more: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Sorry, my bad. I see you solved the kata so I guess you found the answer eventually.
This comment has been hidden.
Please use markdown tags to format your code or it's not usable. Refer to the documentation about this and more: https://docs.codewars.com/training/troubleshooting/#post-discourse
Formatting your code in a readable way would be helpul indeed!
Other than that, I suggest you check your if...else syntax. Also, consider whether "better" also means "equal". It should be reflected in the operator.
The main problem is you overlooked this statement.
Your points are not included in the array of your class's points
. Also, your code has some syntatical error.it seems it doesn't matter either including yourself or not. is there any test case for to check none-self-included solution?
This comment has been hidden.
I can't even run the code. I got error code 422. Can anyone help?
This is very uncommon. When it happens, wait a little moment and try to submit it again, generally it's enough (however there is nothing more you can do).
I'm having the same issue.
In test window write class name "MyTestCasesTest" instead of "MyTestCases". Class name must end with the word "Test".
This comment has been hidden.
This comment has been hidden.
I got error: false with data: Kata.betterThanAverage(new int[] {100, 90}, 11)); At same code my Sublime with the same data return true. How?..
Why are you overwriting the
classPoints
andyourPoints
values?This comment has been hidden.
Hint: your code would return
true
forbetterThanAverage(new int[] {4, 1000}, 3)
, when it should've returnedfalse
.This comment has been hidden.
the for loop should be closed earlier, before if
I feel like the case that you're the exact average should be included. It is not tested for, as far as I can see. My understanding is that with the "<" or ">" operators the top solution would return nothing in case you're exactly average. Otherwise a lovely Kata, thank you!
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Code testing fails half the time! I checked every example in VS Code and everything works! What is the problem?
For attempting to resolve this issue, these translations were made to implement
false
fixed and sample tests:clicking "this issue" just brings us to this page again
That's janky; it should show up ejini战神's issue for this kata. Try this link
it's the same. It think it's enough if you mention the previously described
issue
by ejini战神Approved all, thanks for the contributions!
Julia translation with snake_test
I pass the first 3 'sample tests' but fail one of the next 40 randomized tests on submission and cannot explain why
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You have an error in your reduce function. You are never actually getting anything for your variable
sum
, it will always beundefined
and so your function is always returningtrue
Also, this is a question, not an issue.
closing
This is not tested but casually.
It doesn't matter if you do or not, the answer is the same.
Missing sample && fixed tests for
false
condition (your points less than or equal to the class's average) inMade all translations for these languages fixing that issue (see suggestion here). Please check it up and approve it if it's possible
^^
This comment has been hidden.
Why? The average of students is ~60, and your score is 75, and last time I checked 75 > 60 :P The test case is fine.
This comment has been hidden.
Julia version should use snake_case.
Performed in this translation, please check it out
^^
Are the test cases randomized for everyone? I ask because I went by the description, but noted the "best" solutions do not include that "added" bit.
You do NOT need to add your own score x. Proof : The mean of the classroom (without your own score x) is : m1=(x1+x2+...+xn)/n. The mean of the classroom (includind your own score x) is : m2=(x1+x2+...+xn+x)/(n+1)=(nm1+x)/(n+1). If you know that m1<x then you know that m2<(nx+x)/(n+1) i.e m2<(n+1)x/(n+1) and finally m2<x. Same proof for >.
This comment has been hidden.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
The error message is
True should equal False
and it means your function returnedTrue
when the expected value wasFalse
Thank you for the information. I will look into this some more.
some one please help me how to submit ???
After you pressed Test and then Attempt, the Attempt button becomes Submit button
I need to start crunhing examples by hand. Been burned several times by making the problems harder than they should be.
This comment has been hidden.
This comment has been hidden.
One of the test case wrong
test.it("better_than_average([2, 3], 5) should return True")
andtest.assert_equals(better_than_average([2, 3], 5), True)
should be
test.it("better_than_average([2, 3], 5) should return False")
andtest.assert_equals(better_than_average([2, 3], 5), False)
Not an issue. All the tests are correct.
One of the errors you might have done is that you did not include your points in class size
This comment has been hidden.
You do NOT need to add your own score x. Proof : The mean of the classroom (without your own score x) is : m1=(x1+x2+...+xn)/n. The mean of the classroom (includind your own score x) is : m2=(x1+x2+...+xn+x)/(n+1)=(nm1+x)/(n+1). If you know that m1<x then you know that m2<(nx+x)/(n+1) i.e m2<(n+1)x/(n+1) and finally m2<x. Same proof for >.
Haskell translation
This comment has been hidden.
Mark your code as spoiler next time. Also, please use Markdown formatting for it, like this:
It will turn into a nice code block.
=+
and+=
are different. Check how (and where) you're calculating the average too.yes i got it! thanks alot , it works :)
but i did not find any information about ( =+)
Thanks alot
That's because it doesn't exist as an operator ;)
😁😀
CoffeeScript translation Crystal translation Dart translation Reason translation TypeScript translation C++ translation
Racket translation
This comment has been hidden.
Not an issue. Your code is wrong.
Thank you, relooked at it and saw my error.
my apologies.
This comment has been hidden.
Please, mark you comment as having spoiler content next time.
It's been already asked and answered below.
Sorry,did know! Noted for the next time.
You do NOT need to add your own score x (but you MAY, as written in the description). Proof : The mean of the classroom (without your own score x) is : m1=(x1+x2+...+xn)/n. The mean of the classroom (includind your own score x) is : m2=(x1+x2+...+xn+x)/(n+1)=(nm1+x)/(n+1). If you know that m1<x then you know that m2<(nx+x)/(n+1) i.e m2<(n+1)x/(n+1) and finally m2<x. Same proof for >.
This comment has been hidden.
In which language?
did it in C# Haven't had a look on the other languages, but if they have the same only happy pathchecking testcase, then I'd suggest the same for those.
PS, seems it has been added now in the C# kata
[TestCase(new int[]{100,90}, 11, ExpectedResult=false)]
This comment has been hidden.
Paste your code using markdown formatting and mark the post as having spoiler content.
This comment has been hidden.
In Python, booleans are
True
andFalse
, nottrue
andfalse
.There are other problems too, why are you overwriting the argument? The loop never runs and even when you fix that, your loop will only run once if you have your if/else like that.
So this is more of a general question. I've been studying JS for 3 months, yet had some issues solving this problem. Can anyone give some suggestions on how to get through the growing pains of JS?
This comment has been hidden.
Try to phrase a question. We're here to support you but not to analyse your code.
If you're having trouble with small tasks (i.e. your code is not a huge wall of text nobody would bother looking at) you may post it in a comment with a spoiler checkbox ticked so that somebody could take a look at it, and tell you if your approach is wrong or the solution is buggy.
Lua translation is available.
Julia translation kumited.
PHP translation kumited.
NASM translation
It stand in descripton: "Return True if you're better, else False!" But first basic test in Python indicate you mean: "Return True if you're better or equal, else False!:
"Your points are not included in the array of your classes points. For calculating the average point you may add your point to the given array!" need test for this case Test still pass in both cases: with "yourPoints" in "classPoints"array & whithout them.
It does not matter. You could add your own points 1000 times and still pass the test (as long as you don't run into any rounding errors).
You do NOT need to add your own score x. Proof : The mean of the classroom (without your own score x) is : m1=(x1+x2+...+xn)/n. The mean of the classroom (includind your own score x) is : m2=(x1+x2+...+xn+x)/(n+1)=(nm1+x)/(n+1). If you know that m1<x then you know that m2<(nx+x)/(n+1) i.e m2<(n+1)x/(n+1) and finally m2<x. Same proof for >.
In the first sentence it says we have passed the test. In one of the example tests we scored a 9 and it appears the points are out of 100. This seems a very generous pass/fail margin!
It's better than the average, if the average is less than 9, then no problem. Pass the test means you returned the right value, not that you passed with 9/100.
This comment has been hidden.
Why is average int? Your function is int and you're returning a string.
Not a kata issue, fix your code.
This comment has been hidden.
What can I say? I'm a miracle worker ;)
java.lang.AssertionError Runtime Error Occurred
In Simple Java Test:
public class Kata { public static boolean betterThanAverage(int[] classPoints, int yourPoints) {
return true;
} }
Both assertTrue and assertFalse will throw an AssertionError when the result is not what was expected, I think using AssertEquals would be a better choice. So I've edited it. Try again after clicking reset if you don't see the changes.
This comment has been hidden.
I felt in order to calcluate a proper class average my own points had to be included in the average. So in calcuating the sum I added in my own points and divided by the new array length. The tests still passed, I am wondering if the author of the Kata had that in mind when he added that comment at the end of his Details.
really nice kata, I really enjoy it :)
Java translation and C translation kumited.
It seems these translation were approved at some point. Note that using assertTrue and assertFalse was a very bad idea.
Replaced
assertTrue
andassertFalse
byassertEquals
I know, I did it for Java, don't know if any other language has the same problem.
This comment has been hidden.
The description is the same for all languages and the exact spelling differs in some languages.
This comment has been hidden.
The results are the same! Aren't they?
It doesn't change the situation. Suppose your point is larger than the average.Adding your point increases the average but still smaller than your point.
Because they know basic math. 😉
You do NOT need to add your own score x (but you MAY, as written in the description). Proof : The mean of the classroom (without your own score x) is : m1=(x1+x2+...+xn)/n. The mean of the classroom (includind your own score x) is : m2=(x1+x2+...+xn+x)/(n+1)=(nm1+x)/(n+1). If you know that m1<x then you know that m2<(nx+x)/(n+1) i.e m2<(n+1)x/(n+1) and finally m2<x. Same proof for >.
I tried this code and it gives some strange errors please check why it is not passing
function betterThanAverage(classPoints, yourPoints) { var TotalArray = 0; for (var i in classPoints) {TotalArray += classPoints[i]}; var classavg = (TotalArray)/(classPoints.length); //return classavg;
var classavgwithme = (TotalArray + yourPoints)/(classPoints.length+1); //return classavgwithme;
if ((classavg < yourPoints) && (classavgwithme < yourPoints)) {return "true"} else { return "false"};
}
You're meant to return the boolean value of true and false, as opposed to the string representation of the boolean values that you're currently returning at the moment.
This comment has been hidden.
this has been fixed
marked as resolved
Did it without calculating my_points in the array. <- Didn't read it correctly just did the thing. Maybe you want to design a test which prevents that you can pass without adding your points.
Or maybe tell us whether your_points is included in class_points.
Hi !
Your description says that "There was a test in YOUR class", but in test cases in classPoints array there is no number that is equal to YOUR mark (yourPoints). I've noticed, that all test passed in both cases: we add yourPoints to total sum of points and than divide on (classPoints.length + 1) and in case when we assume, that yourPoints is a part of classPoints and divide just on classPoints.length
This is totally right and I never thought about this. Thanks! I will change the final solution, the test and I'll rewrite the description so this will be more clearly!