7 kyu
Beginner Series #3 Sum of Numbers
14,841 of 218,270Vortus
Loading description...
Fundamentals
Algorithms
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.
Incorrect answer for a=5, b=-1: expected 4 to equal 14
Yes... -1 + 0 + 1 + 2 + 3 + 4 + 5 = 14
This comment has been hidden.
kata hint != kata suggestion
This comment has been hidden.
PHP translation
This comment has been hidden.
The question seemed so easy at first, but it ended up being more difficult.
The JavaScript solution was very good practice for me -- I thought it was going to be a cake walk but I had to think hard!
Thanks for the passed / not passed messages (C++) :)
This comment has been hidden.
PERHAPS
instructions are not clear !!!
this is a challenge.
This comment has been hidden.
−1+0+1+2+3+4+5=14
Golang: Not a kata issue.
Lua translation!
Approved.
This comment has been hidden.
Your code fails for -->
(-1, 2) --> 2 (-1 + 0 + 1 + 2 = 2)
I must do not get the task, but according to my understanding for example "in(1, 2) --> 3 (1 + 2 = 3)" result should be 4 instead of 3, as "in(1, 2) --> 3 (1 + 1 + 2 = 4)". Could someone explain why is it 3 in this case?
The numbers between 1 and 2 including them are 1 and 2 and their sum is 3. Where did you get 1 + 1 + 2?
OMG! Thank you :) I don't know why, but my brain got mixed up wanting the sum from the first number to 0 and the second number to 0. Guess I need to brush up on my reading before diving into Python ><
So if a=-1 and b=-12
the code I am supposed to write adds the numbers in this sequence: -1 + -2 + -3 + -4 + .........-12?
range function wont work if value "a" is bigger than value "b"
NVM I got it.... Sheesh this was a good one, very tricky hahaha, I found the solution by answering my own question... Abashwe....
as I can see from test example, we must get 615087.0 from sum of (668,1294) and I completely don't understand how I can get this sum with these numbers, because it doesn't look like a sum at all. And it would be great|fair to add such example with 3- or 4- digit numbers in instructions
I really didn't get what it must to be done on this kata. It's not a simples sum algorithm
just relook at the instructions a bit deeply.
This comment has been hidden.
That is what you call
Undefined Behavior
. Yoursum
variable is not initialized, so it can be anything, depending on the phase of moon.Your code failing is not a kata issue.
This was a fun one.
This comment has been hidden.
This comment has been hidden.
You have an
else
after afor
. Reading the error message helps:It tells you exactly in which line you have the problem. Before your
else if
you need anotherelse if
or anif
.Did you look at the code I posted?
I did, it seems you didn't. Let's show you your code structure so you can see it:
You misplaced some
}
. Read this: https://docs.codewars.com/training/troubleshooting#post-discourse and use markdown formatting in your code so it's easier to read when you post it here, please.This comment has been hidden.
This comment has been hidden.
Yes, you are most probably missing something, because your solution is not correct, and correct answers to your examples are 127759 and 27440.
You can check following test case:
assert.strictEqual(getSum(2,3), 5);
and see that your solution returns incorrect answer.Ahh, I read the instructions slightly wrong turns out. Thanks for the help!
This comment has been hidden.
I really don't understand what's fun in 'tricky' testcases, which are actually dumb. Wow, the start and the end weren't mentioned, what if I will testcase a > b. What a cool idea.
Since when programming became such dumb garbage? First thing you do is looking at given values. Nah, that's not tricky, that's dumb, you are wasting time, go touch some grass instead.
It's mentioned in the description, read it again. There are no tricky tests, you've been warned about them.
This comment has been hidden.
This comment has been hidden.
Your code is wrong, not a kata issue.
Description should be changed to either remove "which can be positive or negative," or explicitly state that 0 is an acceptable value. Otherwise, that clause sounds like a constraint on which integers are allowable.
No random tests in
C#
Java
This comment has been hidden.
Your code doesn't return anything, hence "expected undefined to equal 14"
it returns 14 'Log 14 .....'
Nope, it does not.
Please see this: https://docs.codewars.com/training/training-example#writing-a-solution
This comment has been hidden.
For a=5 and b=-1, my solution returned: undefined
Ok, I got it. I just copied from VS console.log instead of writing return, thats why it didn't accept my answer. Thanks for help
You see? Your solution returned
undefined
, but should return 14.everything is fine in Visual Studia, but it gives errors here
Mesma erro para mim :(
This comment has been hidden.
This comment has been hidden.
I don't understand this, I ran tests and they all passed but then I get an error when attempting:
"Incorrect answer for a=383, b=307: expected 690 to equal 26565" ?? what. In the question it said if a and b are equal, return a or b, otherwise find the sum (383 + 307 = 690)??
Why the lower rating on this Kata? It is a sound challenge for the ranking, imo.
in python there is a problem whit the test code. it tries to import something and brings an error
You should not modify the function name as it is binded with the tests, not a kata issue!
Something is wrong. "Incorrect answer for a=5, b=-1: expected 4 to equal 14". And other wrong outputs.
Why do you say this is wrong?
-1 + 0 + 1 + 2 + 3 + 4 + 5 in fact equals 14, perhaps you misunderstood the statement
Ah yes, I really misunderstood. Thank you for your help.
This comment has been hidden.
Your code is wrong:
And the kata is fine:
Read the description and the examples again.
This comment has been hidden.
@fateevanastusha It seems you are just adding the 2 numbers? With a=5, b= -1, you are adding 5 + (-1) = 4?
The kata is asking for the sum of all numbers between those inclusive values not just the sum of the 2.
So, here, with a=5, b=-1, the result is looking for
-1 + 0 + 1 + 2 + 3 + 4 + 5 = 14
. etc.This comment has been hidden.
"My solution does not work" is not a valid kata issue.
Your solution has a bug and handles some inputs incorrectly.
this kata is so confused!!! i undertood that the output shoud be the explanation....
This comment has been hidden.
Please write in english. Not a kata issue.
Нужно вывести сумму чисел в промежутке от a до b, не сумму a + b
The function is supposed to return sum of numbers between a and b, not a + b
This comment has been hidden.
This comment has been hidden.
it means it was expecting -1 but your code returns 0, the problem is that in else if part you are not adding the temp_var, you are overriting it, you should do this instead "temp_var += b++" other parts looks correct
Yes, thank you very much, everything is working well now. No matter how much I looked, I couldn't notice that I missed "+=")
My code is passing the test but not the attempt, any ideas as to why? Have may more people has this problem? I'm using JS.
share your code so we can help you
Cool kata!!!
What should the function return if called with no arguments?
Does that happen? In which language?
This comment has been hidden.
There is no test in javascript like that. All tests include two arguments.
Scala test throws this thing
This means there are duplicate test titles, I'll fix it now.
Should be fixed now :)
Nice kata, thanks ! 🦅
In C version, I can't pass one of the basic tests. Message: "Expected -15, instead got -15". WHY????
It is passing my cases but not attempting
same
Same here!
Same. Strange, non?
there is indeed something wrong with this kata ; namely the test code doesn't really check the description .
Which language? Please elaborate.
nvm , i unsay that :P
This comment has been hidden.
What happens when the input is like this:
in your code?
Ah okay I think I got it, thank you so much!
closing
Somehow I'm passing all 100 random tests but failing a fixed test with this error 'expected -50 to equal -1275'. Not really sure what's wrong with my code or what edge case I'm missing
https://docs.codewars.com/training/troubleshooting/#print-input Print the input values
a
andb
it'll become evident what's wrong with your code.This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#works-but-no
I think in the future having better test cases other then the 2 would be helpful. I'm seeing im getting an error that says expecting 9 to equal 14 but i can't even see the numbers from the random test case so its hard to determine how they are getting those outputs.
This comment has been hidden.
don't understand why (-1, 2) is (-1 + 0 + 1 + 2 = 2)
What about it don't you understand?
The intergers between and including -1 and 2 are -1, 0, 1, 2
If you add them together the -1 and 1 cancel each other out so you are left with 2 + 0 which is just 2
(-1, 2) -> (-1, 0, 1, 2) -> (-1 + 0 + 1 + 2) = 2
(-3, 6) -> (-3, -2, -1, 0, 1, 2, 3, 4, 5, 6) -> (-3+(-2)+(-1)+0+1+2+3+4+5+6) = 15
I noticed that the top rated solution fails to return just one value if both values are the same, as requested in the details.
It's a simple fix but sadly the tests did not test for this specific condition.
There are tests for that, which language are you referreing to? If it is Python, the top solution works just fine in those cases.
D translation
I'm relly sure of my solution. Even tested it outside here and it has been returning the correct answers. I'd like for my solution be reviewed though.
try printing your rangeList just prior to the return statement(s) and see what you get
I sure did. I understand everyone's solution but can't relate it to problem.
after running multiples tests, does your rangeList really contain the values you expect it to?
Yes
I just just ran my code manually against all the tests given and it gave the expected result. Except there's something about the question I don't understand. I could share my code too
https://docs.codewars.com/training/troubleshooting/#works-but-no Check the fifth bullet point.
This comment has been hidden.
This comment has been hidden.
Same here man.
OMG!! I don't understand condition of thsi kata..... skip
This comment has been hidden.
Потому что оно неверно:(
Update to Scala 3
.
我认为,该题目,描述的有问题,令人捉摸不透,到底是输出一个字符串还是输出数字和
从标题可以得知是数字和(
sum
), 题目还有模拟测试也有这些例子python fork with:
Approved
Go translation
Approved!
This comment has been hidden.
Your code is incorrect; unfortunately the pre-loaded basic tests have been badly thought-out and aren't general enough they are allowing your incorrect solution to pass because they are so specific.
It seems that your code currently is summing
a
andb
rather than summing all the integers betweena
andb
.I thing the is broked, the numbers -1, 0 were passed, but the test grt failed because the result is not '-1 + -1 = -1', but the right way to be is '-1 + 0 = -1'. It's just me?
It's you, indeed. Only return a number, not a string, your code is returning
'-1 + -1 = -1'
instead of-1
for that testInteresting question, there are some tricky edge cases, the author should have mentioned them in the examples.
this is just badly written
This comment has been hidden.
Maybe this:
Hi. Please use markdown tags to format your code or it's not usable, see there: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
This is not a kata issue. If IntStream isn't recognized, it means you didn't import it. These imports may be hidden in your IDE.
It worked in a previus kata without import
But thanks for you reply, I'll keep an eye on it.
This comment has been hidden.
when ı press the test button the result : You have passed all of the tests! :)
but whe ı press the attempt button it shows some problems.
am ı need to use attempt button or just skip after press test button ?
See the documentation: https://docs.codewars.com/getting-started/solving-kata
thank you
I'm having the same issue. How did you solve this?
Did you read the documentation?
Same.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#works-but-no
Thank you.
This comment has been hidden.
main.cpp:9:5: error: conflicting types for 'main' int main(int, const char *[]) { ^ ./solution.cpp:17:5: note: previous definition is here int main() ^ can anyone tell me that solution
Use the initial code, don't create a main method:
thanks for the help.😁😁
This comment has been hidden.
Always initialize your vars.
I got it! Thank you!
This comment has been hidden.
:)
This comment has been hidden.
please don't post solutions on discourse (even if you have the flagged it as spoiler)
there is a separate solutions tab where you can see yours and other people's solutions
This comment has been hidden.
So what is the issue?
what's the error on your editor say?
this might sound very stupid, but i was making a funny mistake i was passing in all the integers in the test cases into my function like this
print(get_sum(-1, -1,) -1)
and i kept running into a tuple error
Strange task description. I thought that I should return the answer as a string with a description, but in reality, only an integer sum.
is the exact words from the desc.
I was a bit confused too...
Good example for a beginner series
COBOL translation.
approved
No random tests in Python.
There are random tests now.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting you're using global vars there.
Thank you.
This comment has been hidden.
Please use a spoiler flag when posting code. And use markdown tags to format it. See there: https://docs.codewars.com/references/markdown/#code-block
This comment has been hidden.
Because
console.log
doesn't return anything, remove it. And then you have some other problems in your code, the 2 ifs have the same condition.This comment has been hidden.
This comment has been hidden.
Not a kata issue, it's a problem with your code,
minNum
isn't properly initialized sometimes. Mark your post as having spoiler content next time, read this, please: https://docs.codewars.com/training/troubleshootingThanks @Chrono79. it helps to see that someone figured the problem in my code, but can you better highlight/explain the problem please. gone back to review my code and still not understanding how you mean by "minNum isn't properly initialized sometimes". Please
This comment has been hidden.
BobtheLantern explained the problem in detail, I'll add, don't abuse ternary operator, it might look cool and short, but when it fails like in this case, you'll have troubles figuring out why.
This comment has been hidden.
The tests are fine, your code is wrong, see the last example in the kata description.
Thanks, yeah i missunderstand the excercise, i start over and did it, thanks.
Maybe you could add more examples to the Kata description to show examples for the program's behaviour when two numbers have a greater difference than 1
there's the last example there
Why should it be -229? From -359 to 130 the sum should clearly be bigger than that.
Reread the question. He wants you to take -359 + 130 + -229 + -228 + -227... that would equal the -56105 Hope this helps :)
А откуда взялись -229 и -227
f...g tests. 0 should equal 14 0 should equal 127759 0 should equal 44178 What sould I can tested in this cases, man??? Can you wrote more tests for save our time??
It seems your code is wrong with that, print the input values. Just a guess, hard to know without actually seeing your code.
This comment has been hidden.
Hi, please read this: https://docs.codewars.com/training/troubleshooting/ a problem with your code is not a kata issue. About the error, for some values, your function is not returning and the default returned value when that happens is
undefined
, useconsole.log
to print the input values and check/fix your code.Thank you for the answer!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Can you share your code? We'll see if your code is 'right' after.
when i test, all of the tests have passed, but when i attempt have a error about timed out of execution. Can anybody help me please. ps: the language is javascript.
Not sure about js but I experience the same in python. The system has a prompt about that, and it is usually because our codes are inefficient (it takes too long for the algorithm to process the questions). You just have to simply refine your code, though that is still challenging.
This comment has been hidden.
Hey guys, I'm getting like this.
Any idea what could be the problem?
Are you always returning 0? If so, why?
Try to debug your approach over the Python IDE - step after step.
Note: a and b are not ordered!
This comment has been hidden.
Does not work how?
Did you read the FAQ? https://docs.codewars.com/training/troubleshooting/
Hi, Can I see the output in the failed test in attempt? I have a one failed test and I don't know what is
The output say: 1 should equal 17 It is the last test, is test equal
in what language?
In python
You can use a print statement as the first line of your code:
Thank you so much
I've got error: TestPositive Test Failed Expected: 14 But was: 15
But next tests successfully passed: Assert.AreEqual(14, s.GetSum(2, 5)); Assert.AreEqual(14, s.GetSum(-2, 5)); Assert.AreEqual(-14, s.GetSum(2, -5)); Assert.AreEqual(-14, s.GetSum(-2, -5));
Assert.AreEqual(14, s.GetSum(5, 2)); Assert.AreEqual(14, s.GetSum(5, -2)); Assert.AreEqual(-14, s.GetSum(-5, 2)); Assert.AreEqual(-14, s.GetSum(-5, -2));
No other nubmers can give that sum. What's wrong?
Not a kata issue, why don't you print the input to debug your code?
I'm new, can you write me how can i do this? I see only Output after press Attempt.
Use this as the first line inside the function:
This comment has been hidden.
Because
127765 - 6 = 127759
The author has used the word 'too' instead of 'two' in the description, making this kata way harder to understand that it needed to be.
Hope this helps everyone.
Fixed
This comment has been hidden.
Hello, please, stop posting solutions in Discourse.
we have better ways to do it in python
This comment has been hidden.
This comment has been hidden.
Not a kata issue, but a problem with your code. Is
array
an array?Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Can i get some answer why i got some confusing result when i'm attempting to test it, please enlighten me. This is the only one failed in the test.
-50 should equal -1275 Log -1 -5 # This is the a and b -15 # i print the sum so that i can understand why it failed
Read the description properly:
So sum of numbers in the range of, and including,
a
andb
.Is it -5 -4 -3 -2 -1 = -15? sorry if my understanding is wrong
This comment has been hidden.
The failing test is above, not below.
I'm still confuse, maybe my code is just long and it cause wrong things in place but thanks for solution! I'm still not good in one line code and that dissapoints me. And thanks i know now my wrong syntax! My wrong
The log appears above the test result, you're confusing the error message of one test with the log of the next one.
Crystal translation kumited :) (author inactive)
Something wierd going on when I click submit . I already tested all cases and everything is fine . but when I click submit it's showing me failed weird test cases that are not there .
" Test Positive Test Passed: Value == 1 Test Passed: Value == 3 Test Passed: Value == 14 Expected: 127759, instead got: nil Expected: 44178, instead got: nil STDERR /runner/frameworks/ruby/cw-2.rb:60:in
block in describe': Expected: 127759, instead got: nil (Test::Error) from /runner/frameworks/ruby/cw-2.rb:46:in
measure' from /runner/frameworks/ruby/cw-2.rb:51:indescribe' from /runner/frameworks/ruby/cw-2.rb:202:in
describe' from main.rb:10:in `Hey moderators, please take a look at translation queue for this kata — there's a whole pile of translations to approve, and the author is inactive for almost two years.
There is currently only one translation awaiting approval.
There seems to be something strange going on with this one.
When the tests are ran with the basic inputs, they pass, however during the full attempt, I fail almost all them with messages like this:
Testing for a=-573 & b=308 Expected: -116865, instead got: -265
Now, the last time I checked, when you add -573 and 308, your sum is -265, which my script is returning, however the test seems to expect some arbitrary number - in this case below -100000?!
Someone please help me out...
The question is asking you to return the sum of ALL numbers in the RANGE of
a
andb
.For example, ifa = 1
andb = 5
, then return 1+2+3+4+5.Im having issues as when i run it on Code it works but i dont know the test imput on the submit
are all int? or test using other type of number?
Print the input to see what it is.
This comment has been hidden.
Hello, please don't post solutions in kata's Discourse. There is a Solutions section for that matter, and even there, mark your post as having spoiler content when they do.
This comment has been hidden.
Presumably you also used different input, making it not comparable.
No, I tried input from the first test: 0, 1
Hi friends, i have a case test on my class that talk the below, the result of method get sum with values -50 and 0 should be -1275 i don't understand this case test, the result is correct ? more somebody with case test?
This comment has been hidden.
What does it mean in the instructions when it says Note: a and b are not ordered! What does it mean to be ordered
a
can be greater thanb
in some tests. Depending on language, this could present some issues with how you implement your solution.Will it affect me if I use python
Don't mind the late reply, but yes, especially when you will be using the range() function
Pascal translation.
approved by someone
This comment has been hidden.
This comment has been hidden.
...find the sum of all the numbers between...
should be
...find the sum of all the integers between...
This comment has been hidden.
can i see the random tests?
See how to print the input here: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-input as B1ts already told you in "Can we divide it?"
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Thanks for the tip!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Read the instructions again and see the last example, you're not doing what it says.
This comment has been hidden.
arguments
? Don't use that... It's old fashion and the best way to do bad things.replace
isn't a method ofArray.prototype
=> ???replace
to the output ofpush
, which is a number... (see MDN documentation) => ???!??What can I use instead of arguments?
It should have been reduced, thank you.
My biggest confusion is if I can have #for after else statement.
arguments
thing, I mean)arr
thing, just a number that you'll update, then return in the end.Awesome. I get you. I couldn't think of a way of adding arguments to an array. Can I say [...a,b] or [a,b]?
[a,b]
, yes.This comment has been hidden.
Please read this. Your function should return the result, not print it.
I'm new at coding and i really appreciate your help but now i'm also stuck casue I changed every print to "return suma " but now it doesnt give back any result. I know that it stores this value somewhere but how i can call it and make it to appear to the screen as a result of this function (without print)?
If you changed all your
print(suma)
forreturn suma
you should see here the results instead ofNone
in the CW trainer. If you're testing your code in another place, you'll have to print the returned value to see it, like this:print(get_sum(0,1))
. There is a problem with your code, check how you defineliczby
in one case and in another, you missed something in one of them.This comment has been hidden.
Surprisingly easy for 7 kyu
This comment has been hidden.
Use markdown formatting when posting code to keep indentation.
This comment has been hidden.
It doesn't work @Chrono79
They're backticks ``` not single quotes ''', and you're using python, not javascript
```python
#your code here
```
This comment has been hidden.
Print the input (it'll appear above the test result) and you'll see your code doesn't work when a > b and both are positive. And why have you two nested loops with the same indice? That's weird.
Don't forget marking your posts as having spoiler content when they do, please.
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.
It's working just fine for me, try clicking reset if you see
GetSum
in the sample tests.I've just checked and it's working fine. Thank you for fixing that bug.
Scala translation
Approved
This comment has been hidden.
Holy, reading such a code is pain for eyes dude.
This comment has been hidden.
using Clang I got this error: Expected 14, instead got 14 what seems to be the problem?
This comment has been hidden.
Not an issue. Accessing uninitialized variables is UB.
thanks, for some reason, I thought every C variable types has its default value. maybe I was thinking about DB...
This comment has been hidden.
No, that's not what you have to do, read this again:
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Read that part again.
This comment has been hidden.
What you've shown is a demonstration of an arithmetic sequence/progression. A few older comments in this thread contain a link to the Wikipedia page on the concept.
(Incidentally, you'll find that a lot of the more established kata here present good opportunities to apply mathematical knowledge. Learning some theorems and principles like this will be a huge help in solving kata of this nature, even if at the very least you can come to a greater understanding of what's involved in the solutions.)
This comment has been hidden.
Prolog translation kumited. (author inactive)
This comment has been hidden.
Wrong kata.
This comment has been hidden.
b
may not necessarily be larger thana
. (a
could be larger thanb
)Ok so then is my code wrong or do I just need to adjust the range? Thanks for all the help!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You should discuss these things within solutions' tab, and not here...
Julia translation
This was funny
The name of the JavaScript function should not be
GetSum
with an uppercaseG
. It should begetSum
with a lowercaseg
. It is common accepted pattern to only use identifiers starting with an uppercase letter (PascalCase) for constructor functions, or components in Vue.js, React and similar frameworks. "Normal" functions should usecamelCase
.Changed without rendering all current solutions invalid.
Log 1 None should equal 1 Log -1 None should equal -1
Your function is printing instead of returning the result.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
That's not how you sort numbers.
Hint:
This comment has been hidden.
Stop posting your solutions, please.
This comment has been hidden.
This comment has been hidden.
And how are you adding all the numbers between
a
andb
like that? See the last example, your code returns1
. The tests are ok, it's your code what's wrong.There is issue in attempting even it pass all the test?
same for me, pass the tests, but when attepmting only half is ok. I have no way to check the input of those tests of some resone so I have no way of figuring out what went wrong.
This user made a lot of frustrating and not working katas, is there a way to block katas from a single autor?
He (or she) only has 5 published and approved katas and they all work.
No.
And as you can see, the problem was in your code.
Maybe we can change the text a bit? It reads a little weird... How about something like this:
Given two integers a and b, which can be positive or negative, find the sum of all the numbers in between (including the start and end) and return it. If the two numbers are equal return a or b.
Note: a and b are not ordered!
That may work, let me reset...
Thanks! I had no idea what I was supposed to do here LOL
leave it, because this send me error on import. tnx, but its not java.
This comment has been hidden.
Why are you returning 1?
I don't know :) Thanks! :)
Please, NASM Translation
This comment has been hidden.
This comment has been hidden.
why then does it work for me with the same valueswhen I enter it into the python development environment?
Google translate
Because you're testing the wrong thing, and
a=5, b=1
is not the test which you're failing.This comment has been hidden.
Not an issue. If your code doesn't pass the tests, it's wrong.
That helps. Thanks a lot.
Tests pass without issue, but submitting fails all random tests in Typescript. I've written an astronomical amount of my own tests, which are all passing. When submitting my answer, it tells me
expected 0 to equal x
, wherex
is the expected result. Mathematically, this doesn't make sense, especially when my tests themselves are passingThat's weird, I've tried my js solution in typescript and it passed with no problem. Why don't you post your code using proper markdown and marking your post as having spoiler content? If your code is failing only some random tests I would tell you check the note:
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Thank you so much! I appreciate it.
I have a pending translation for R if anyone wants to check it out and maybe approve. I think technically I can approve it myself but it's my first translation... I'd rather have another set of eyes.
LINK
Basically cloned the Python version and added some random tests.
This comment has been hidden.
No return statement. Also, it seems that your
count
is global which will lead to wrong results.Would someone please tell me why I kept getting this error? The code runs as requested perfectly on my Python 3.6.3 IDE as well as in Pythontutor.com. Thanks in advance.
Traceback (most recent call last): File "main.py", line 6, in Test.assert_equals(get_sum(5,-1),14) File "/home/codewarrior/solution.py", line 22, in get_sum (a, b) = swap_variables(a, b)
TypeError: 'tuple' object is not callable
See the python versions available for this kata, they're less than 3.6.
Damn, so I just wasted my time on this kata? :( I guess I'll have to rewrite some of the code...
You should be able to select Python 3.6 now. I don't know if that error has anything to do with Python version though.
Could you post your code in a comment (with a spoiler tag)? I think there's a problem with your code. In fact, many people say their code works in IDE but it always turns out the code is simply wrong.
Apart from that, you can swap variables in Python like this:
a, b = b, a
.'Looks like you've solved it'
This comment has been hidden.
Yes, your function should return, not print.
Guys please note that in Ruby language
get_sum
method is bad style for method name. Justsum
orsum_of
orsum_of_two
is much cleaner. No need for prefixes likeget_
orset_
.This comment has been hidden.
Read this and mark your post as having spoiler content when pasting code.
This comment has been hidden.
Maybe
for i in range(a,b): a+=(i+1) ... for i in range(b,a): b+=(i+1)
Thanks
This comment has been hidden.
Spoiler tags
My apologies.
But could you kindly inform me what's wrong istead of :
saying trash multiple times isn't helpful :)
I will fix it immediately :)
O_o
I will await your next reply. in the mean to fix things that need fixing.
Anonymous I've made a fork with all the tests with Expected X, instead got Y. See if you can use it.
Chrono : I'm working on it. I apologize for the mess. I am new and don't know much about codewars. Thanks for the fork.
I think I fixed most of these ?
Could you take a look @Chrono79 : Link
get_sum(-504 , 4)
should return-127250
fix that sample test too.Chrono79 : Annnnd forgot that. Thanks doing it right now.
TrashGarbage value is garbage value. If you don't know what this is, then you should learn the language before writing in it.Either my interpreter is wrong telling me that I receive numbers as big as ±(1-2) billion as an
int
arguments, or you've fixed nothing.And yes, I can pretty much see the speech patterns of
___i
in your messages.Could anyone approve my fork?
Thanks, Chrono.
It looks to me like the
c
kata has some incorrect unit test. The sample testcr_assert_eq(get_sum(-504 , 4), -127755);
looks incorrect to me - shouldn't the sum be `-127250? It looks to me like this test should be replaced with one of the following:cr_assert_eq(get_sum(-504 , 4), -127755);
cr_assert_eq(get_sum(-505 , 4), -127755);
Similarly, when attempting to submit a solution, I get some seemingly incorrect errors, e.g.:
The expression (get_sum(-50 , 4)) == (-1265) is false.
But that doesn't look false to me - it looks true.
What gives?
Both things corrected. When you got
The expression (get_sum(-50 , 4)) == (-1265) is false.
it means the function didn't return-1265
.C translation kumited, awaiting your approval.
Here
Review and approve :)
This comment has been hidden.
Could you check http://criterion.readthedocs.io/en/master/assert.html a little more? I resist to believe there is no way of showing the expected and actual values.
Hold on, Is it still giving away the solution ?
No it's not, but in other languages you can see the actual and expected values so you can see directly what your function returned.
Could be the fact that I am new to this framework.
@Chrono79 : Fixed for one translation, sum of digital roots. Fixing it for others right now :)
@Chrono79 : Kindly approve this one. I had to make a fork since there were some errors with direct change :)
I went ahead and approved this.
That was I was talking about, I knew there should be a way to give a helpful error message, thank you.
This comment has been hidden.
This comment has been hidden.
How is this a kata issue and not your code's problem?
array.sort() (without a compare function) doesn't work well to sort numbers. Please, read the docs Downvoting my comment won't make you right.
Not a kata issue (check how many solutions there are for js, more than 11000).
This comment has been hidden.
That's far from a snark, your code's problem is a question, not an issue. You chose the wrong category to post your comments, so someone will point it out ;-)
Also, given how your initial tone is so condescending, I'd say it was deserved ;-)
Shell translation with random tests for review
approved
This comment has been hidden.
(You should format your code)
Firstly there's no proper
sumOfNum
declaration, and I'm surprised that it's even working for you (is it?). Secondly, your loop is working with wrong bounds becausegiven two integers A and B, which can be positive or negative, find the sum of all the numbers between including them too
. Thirdly, you can'tconsole.log()
afterreturn
- you're trying to perform an operation after the function has already stopped working.I tried to do Java kata, but I got some huge error message from trying to import absolute value method
error message is below: java.lang.AssertionError: expected:<1> but was:<0> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit.Assert.assertEquals(Assert.java:645) at org.junit.Assert.assertEquals(Assert.java:631) at SumTest1.Test1(SumTest1.java:14) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at org.junit.runner.JUnitCore.run(JUnitCore.java:105) at org.junit.runner.JUnitCore.run(JUnitCore.java:94) at io.qualified.junit4.RunSingleClass.main(RunSingleClass.java:12)
This comment has been hidden.
What's the issue?
Not an issue
This comment has been hidden.
Wrote the programm how the hell should i execute it there is no run button
by using ctrl + s
I just used ctrl + enter
This comment has been hidden.
Please mark your post as having spoiler content (I did it for you this time). And read this about how to format your code. If you click
Solutions
once you've solved the kata you can see the code from other warriors. See sandboxj's solution (you'll have to scroll down a lot).This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Your function will be called many times. Think about what happens at the second call ;-)
This comment has been hidden.
Process exited prematurely with a SIGKILL signal.
I don't know why, frankly...
That sounds like an infinite loop.
I think the details should contain at least one example that shows what happens for number that are not siblings, e.x. GetSum(-3, 4) // -3 + -2 + -1 + 0 + 1 + 2 + 3 + 4
GetSum(-1, 2) == 2 // -1 + 0 + 1 + 2 = 2
like that example?Thank you bro, I didn't get the kata at all
Hi, after writing the code in python and running it, I have passed both the tests, but when I click the attempt button, it given me one error, stating 4 equals 14. How do I remove this? Thanks in advance. #noob
It means your code is doing something wrong. Print what you code is doing to make it easier to debug.
I'm solving in JavaScript. My code works in all of my practice tests, all of the random test cases, and it works in all but 4 of the submit tests, I can't say why they are throwing errors, because I can't see the values being tested, but my code works. The 4 errors are saying that 1 is returned instead of the answer, but I can't see how that mathematically possible, seeing as there are finite testable ways of generating what the expected answers are, and I've tested them successfully. Please take a look and see if there are errors in the tests, if that's possible, or at least share the test parameters
I'm getting the same errors
Use
console.log
to see what the input values are. It seems you're ignoring this note:I'm impressed at the one-liner solutions I've seen, quite nice.
hi niggers
Hi,
Also having a similar problem as @cheneyshreve. Any help?
Hi,
I pass the sample test but the get these errors: Test Passed: Value == 1 Test Passed: Value == 3 Test Passed: Value == 14 Expected: 127759, instead got: 509 Expected: 44178, instead got: 444 Any ideas on how to troubleshoot? Thanks. complete newbie to codewars..
Without seeing your code in spoiler, we cant help u, read this for more info
It reports syntax error on the test.function in python
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.
This comment has been hidden.