7 kyu
Sum of Odd Cubed Numbers
4,603 of 10,848elliottmck
Loading description...
Fundamentals
Functional Programming
Arrays
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.
Description Suggestion JavaScript
If the input array contains anything other than integers, then return undefined.
Iterate through the array cubing each element meaning e3 or
e*e*e
.Grab only the odd cubed elements and return the sum.
The returning undefined aspect of this Kata is a hindrance and it's problematic tbh
Why would this test suppose to return 0 ?
Test.assertEquals(cubeOdd([-3,-2,2,3]), 0);
3 * 3 * 3 = 27?
It returns 0, as it is the sum of cubed odd numbers, where -3 cubed is -27 so it is infact:
-3 * -3 * -3 = -27 and 3 * 3 * 3 = 27 therefore -27 + 27 = 0
but
so, what if number is float (not equal to its integer part)? It is a number, but it is not an odd number (even or odd are defined only for integer) Seems like, text might be "The function should return undefined/None/nil/NULL if any of the values aren't integers" and there must be any test with float (at least there are none of those in python version)
Fourth basic test failed while all random tests are passed in Python. Can anyone help?
I would say you have two possibilities:
Make your choice fellow.
python considers True and False as numbers (1 and 0)
so you are probably failing a test there
Pride is lost but I've understood what were wrong then. Thanks!
This comment has been hidden.
That's a problem with your code, not a kata issue. Print the input and mark your post as having spoiler content next time. Read this: https://docs.codewars.com/training/troubleshooting
JS:
JavaScript has both
undefined
andnull
.Added specific description block for JavaScript
This comment has been hidden.
Great try - except example
y, errors in test: assertEquals(0, FindOddCubes.cubeOdd(new int[] {-3, -2, 2, 3})); Must be -19(-3^3+2^2=-19, not 0); expected:<0> but was:<-19>
Just a quick feedback : perhaps make the description a bit more detailed :
I had to look up what cubed numbers mean, and perhaps one example wouldn't hurt :)
Maybe it's just me, but I found the wording "the odd numbers" confusing. I thought it meant the odd array entries (ie the 1st, 3rd, etc). It was even more confusing because the first test case gives the same answer. Maybe shuffle the the numbers in the first test case, or make it clear you mean the numbers that are odd.
Same. Spent too much time figuring this out.
This comment has been hidden.
This comment has been hidden.
Rather strange behavior of the checker. Below my Log and test error.
Log
int arr[] = [3, 23, 32, 43] Math.pow(el, 3) = 27.0 Math.pow(el, 3) = 32768.0 sum = 32795
expected:32795 but was:91701
In the Java tests the actual and expected answers are in the wrong order. I've swapped them, so it's working correctly now.
Thank you for raising this question.
This comment has been hidden.
Agreed. I've added this test to the Test Cases.
Consequently the solution above will never pass the tests.
Also, it should be rewritten to be more consistent with numbers versus integers.
I saw some of the "correct anwsers" and they should not be accepted. Please, someone write this test:
Edit:
This chanllenge needs to be rewriten if you really want to return
undefined
if any of the values aren't numbers.This comment has been hidden.
Read the description!
Which I assume is
None
in Python.Anyone managed to complete this in Java? I am not sure how to return 'undefined' from function which return int.
In java you dont have to do that
In Python random tests:
That's interesting because
bool
is anint
but at the same time may not be considered a number. Whatever the intended expected behavior is, I suggest that there should be a static test like this.This comment is old but the problem is still there.
The description should state if boolean should be considered as numbers or return None.
At the monent random tests expect None if there is a boolean in the area but very rarely test this kind of array (usually there would also be a letter in the array)
For Python, I've added a Test Case that combines bools and integers.
I've also added a little note to the Python version that says booleans should not be considered as numbers, just to make it completely clear.
Hi, sorry if this is a really basic question, I'm quite new to the site.
I've tried making a code for this but I keep getting the error "729 should equal None"
Does this mean that cubeodd([725]) should return None? If so, is this because for it to be a "sum" it should have at least two or more components?
If that's the case I added a bit to the code to return None if the input only contains one element. But I still get this issue. I've tried it in a third party program and it returned None with the input of [729]
729 is what was returned, None is what was expected, the argument is not printed by the tests but you can print it yourself if yoy want.
Hi, I've created a C# translation here for this Kata.
I dodn't get it , can anybody please explain me in a easy way?
First, If there is any non integer in array than return None.
Second, I will sort all odd number from array. Then I will sum up the array , than what?
You will sum the odd cubed numbers, as it says in the title.
Hi , english is not my first language so I didn't get this part "odd cubed numbers" . Lets say for one of test case I got 4 as a "sum of odd" number, if I cube it than it will be 64 , which is incorrect. can you please explain me this?
You start by cubing every number (n * n * n). Then add the numbers together IF they are odd numbers. Then return the sum of the odd numbers.
so if your numbers are A, B and C:
(A * A * A) = odd1 (B * B * B) = even (C * C * C) = odd2
Answer would be odd1 + odd2.
Sorry if I've confused things further
Oops, looks like there is something wrong with your test case, my program went all tests wrong ...
Make sure you didn't mutate the input array.
Python, Ruby and Crystal translations kumited :)
Haskell translation kumited. Please accept ;-)
Approved! :)
PHP Translation Kumited - please accept :D
Accepted - Thank you! :)
Need to hard-code in a test case where the sum is 0. Some passing solutions would return
undefined
when0
was expected.Thanks for the feedback. I have added another test case which equals 0 but I'm not sure if this has solved your issue. The Kata is meant to be relatively easy and I am happy for both 0 or undefined to work.
Let me know if you have any suggestions.
Thanks, that corrected the issue.
Oops, looks like the problem still exists. You added another test to the examples, but not to the actual test suite. I won't reopen the issue, but if you add the same test that you did to the examples to the test suite it would correct the problem.
No problem! I have added a test that equals zero into the test suite now :)
Nice first kata! Thanks!
Thank you!