6 kyu
Tribonacci Sequence
61,893 of 160,816GiacomoSorbi
Loading description...
Number Theory
Arrays
Lists
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.
Broo this is so hard how are we suppose to think like that???
Please update the Kata description so we don't all waste Attempts and screw up our stats:
"be ready for anything else which is not clearly specified ;)"
That's an understatement. When n is smaller than the signature array length, you did not specify the desired behavior. I had assumed it was the same expected as n == 0, an empty array. Instead, this is the response:
"Testing for signature: [9.0, 15.0, 4.0] and n: 2 It should work with random inputs too: array lengths differed, expected.length=2 actual.length=0; arrays first differed at element [0]; expected:<9.0> but was:
It clearly expects the the first 2 elements from signature array in this case.
Well, I agree that the " be ready for anything else which is not clearly specified" is really poor style and should not be there, but come on, if the caller requests two elements, then how can be interpreted differently than, duh, returning two elements?
I don;t think it's true. Signature length does not directly affect what are the first two elements of the sequence.
i did not understand what the assignment was.
do you want the signature of a given list of the tribonnaci? it doesn't look like it since you give a signature as input in the function.
I have no idea so sadly I had to look at the comments to understand.
Am I wrong in my assumption that "a signature array/list, returns the first n elements - signature included" should be 4 numbers and not 1? - yes i see the test assumes 1 but I dont see why that is correct?
I think it just means that the signature should be included among the elements that you return, otherwise people might assume that they only have to return the newly generated elements.
you are right I just managed to confuse myself. the statement can be true even when I only have to return one number. I just assumed it coud'nt
the first n (n =1) elements is just the first number of the given siganture BECAUSE the signature IS INCLUDED. I assumed wrongly that the result would be the signature plus the first element.
Input should not be provided as a sequence when it is of fixed size.
I prefer lists/arrays/sequences even for fixed sizes. All languages support them and it is easier to work with them in general.
I fail to see how
[int] -> int -> [int]
is any easier thanint -> int -> int -> int -> [int]
or evenint * int * int -> int -> [int]
, though?In my opinion, this issue isn't big enough to invalidate thousands of existing solutions in different programming languages. It's a fair point for new challenges, though.
Why does invalidating solutions matter though? It doesn't affect anyone, and it's an extremely easy kata so new ones will fill it up fast anyway.
I wouldn't say it doesn't affect anyone. Top solutions would disappear from the board. Seeing your top solution disappear, could have an impact on some, not so much on others.
For me
[int] -> int -> [int]
is simpler. I could acceptint -> int -> int -> ...
but notint * int * int -> ...
because there is no uniform support of tuples for existing languages. My problem withint -> int -> int -> ...
is that it is not better than[int] -> ...
for this kata. If the input were a list with 10 elements, would it still be an option to replace this list with 10 separate parameters? I don't see a big difference between 10 elements and 3 elements.It's literally a tribonacci kata, though? The list is specified to always be of length three, if it had 10 elements then it would be out of spec (and would make a lot of top voted and even reference/author solutions across languages either crash or do undefined behaviour).
If it was the n-bonacci kata then sure, provide
[int]
, but it isnt.My question was about a hypothetical kata where the input is a fixed list with 10 elements. Would you suggest to replace that fixed list with 10 separate arguments?
That depends on the situation, though? There are times when a list will make sense (for example you want to handle those elements as a group), and where a 10-ary function makes more sense (where you don't want to do that - usually when the first thing the majority of solvers do is destructure them out of the list and into separate values).
We also aren't talking about your hypothetical strawman kata, we're talking about this one.
For this kata, a fixed list with 3 elements is better (in my opinion).
3 separate arguments would be acceptable for a new beta kata but I don't think this kata should be updated and existing solutions invalidated.
This comment has been hidden.
Liked it but I feel the description unnecesssarily verbose and confusing.
To anyone having trouble with this kata:
You got this!
Please update the Kata description so we don't all waste Attempts and screw up our stats:
"be ready for anything else which is not clearly specified ;)"
That's an understatement. When n is smaller than the signature array length, you did not specify the desired behavior. I had assumed it was the same expected as n == 0, an empty array. Instead, this is the response:
"Testing for signature: [9.0, 15.0, 4.0] and n: 2 It should work with random inputs too: array lengths differed, expected.length=2 actual.length=0; arrays first differed at element [0]; expected:<9.0> but was:
It clearly expects the the first 2 elements from signature array in this case.
If you're having issues with the buffer when hitting "attempt" try removing any print statements you might have.
kata hint != kata suggestion
On the C version, it only ran one test when I clicked "test" and only ran 2 tests when I clicked "Attempt"
you are confused about how the test framework works. One test can contain several assertions. Both the random and fixed tests have many assertions.
Ah, okay. That's an unfortunate way for it to work.
why ?
the question is phrased for a math student, not a cs student
this question is just poorly written in general.
so that's why I found it easy to understand and still saw people say its "poorly phrased"
I've solved it and the solution is the same as the others. But the solution is not accepted. it took 12 seconds to execute and so it is not accepted
i'm sad
maybe im bad, but all the answers (yours and mine) are same,and every of it marks as: 'None should equal [list]', in log everything is clear
OP solved it, closing. But next time do not modify the input, it is bad practice.
This comment has been hidden.
Your code returns the first n + 3 elements of the needed sequence.
Also, your code fails when
n = 1
andn = 2
This comment has been hidden.
Cuz nothing called array_spice it's array_splice()...
got a little typoed in post
lots of energy focused here on the edge cases. it may be plodding, but i chose to handle those manually. life's too damn short :)
i have error when n = 3, i return back all 3 signature. am i wrong?
this should work, maybe it's a test issue depending on what is the language that you are doing this
This comment has been hidden.
Fixed.
This comment has been hidden.
You cannot extend an integer to a list, you can only append it. Also, your code fails for cases like
tribonacci([1, 1, 1], 1)
(your code returns[1, 1, 1]
whilst the output should be[1]
)The R version does not have sample tests
Replace the contents of the Sample Tests pane with this
Does anyone have any advice or hints to help me optimize my recursion?
This comment has been hidden.
You do not need recursion. A simple for-loop that tracks the last 3 elements' summation of the list will do.
This was a great Kata! Thanks for sharing it with us. As usual, my code spans several lines using if statements while this clever bunch are posting 2 liners :S
This comment has been hidden.
Fixed.
So how should it pronouce in Italian?
tribonacci
This comment has been hidden.
Your code does pass both basic and random tests. However, this is not the proper way to raise an issue, and there is actually no issue unless you demonstrate it clearly. Please read carefully the documentation: https://docs.codewars.com/training/troubleshooting/
Isn't it better to have the three numbers in use stored in the stack (long long a, b, c;) instead of acessing the array every time? Since it's malloc its access is slow, right?
This comment has been hidden.
I assume you're talking about this test:
test.assert_equals(tribonacci([1, 1, 1], 1), [1])
, It's because the test is asking for the 1st element in the sequence, which is 1.This comment has been hidden.
Your code fails for cases like
signature = [2, 0, 1]
andn = 2
. The expected result should be[2, 0]
but your code returns[2, 0, 1]
Read this instruction carefully -->
returns the first n elements - signature included of the so seeded sequence.
"be ready for anything else which is not clearly specified ;)"
That's an understatement. When n is smaller than the signature array length, he did not specify the desired behavior. I had assumed it was the same expected as n == 0, an empty array. Instead, this is the response:
"Testing for signature: [9.0, 15.0, 4.0] and n: 2 It should work with random inputs too: array lengths differed, expected.length=2 actual.length=0; arrays first differed at element [0]; expected:<9.0> but was:
It clearly expects the the first 2 elements from signature array in this case.
I like this one :] Thank you for providing it.
This comment has been hidden.
signature = {8, 14, 18}
n = 23
Submitted: {8, 14, 18, 40, 72, 130, 242, 444, 816, 1502, 2762, 5080, 9344, 17186, 31610, 58140, 106936, 196686, 361762, 665384, 1223832, 2250978, 4140194}
Expected: {9344, 17186, 31610, 58140, 106936, 196686, 361762, 665384, 1223832, 2250978, 4140194, 5080, 9344, 17186, 31610, 58140, 106936, 196686, 361762, 665384, 1223832, 2250978, 4140194}
Test issue: The answer is supposed to be the same as submitted but somehow the test answer start element is not signature.
Remember stating the language where that happens.
This comment has been hidden.
You should return only the 2 first elements of the sequence when n is 2. It doesn't matter the signature has 3 elements. Not a kata issue.
This comment has been hidden.
That's a problem with your code, not a kata issue. Check your loops.
It's not resolved issue, lol, it's still not working while in my IDE everything is fine with current test cases
But your solution seems to pass now?
Yeah, because I rewrite it to the ground and I have no idea why my previous code not working
Well, without seeing your code it's difficult to say why it was incorrect.
In your IDE you didn't tested with the same values that made your code fail. It was when n was 3. There is no issue, that's a problem with your code.
Those are the related lines of your old code.
yeah, I got it now, thx
This comment has been hidden.
all tests are successful, but when I click "ATTEMPT" I get this error Extended_tests Random_tests Expected: equal to [ 10 ] Actual: [ ]
This comment has been hidden.
That's because you messed up the function signature. The corrrect one, present initially in the solution setup, is
function tribonacci(signature,n)
. You changed it in a way which turns thesignature
argument into not a sequence.It's not a kata issue, you need to fix your solution. Also make sure you run testss with version of Node which supports
at
.The tests are being ran with Node18. at() method should not be a problem/missing function.
Please explain why there are two arguments then for this function, when in the test samples you are feeding a single array, since I cannot de-structure. The sequence being an array in the [0] index, the 'n' value being the [1] index.
You are misreading the sample tests. Look how
tribonacci(sig, len)
is called in the sample tests. User solution is called with two arguments, not one.for c++ you also need to #include . Otherwise it will throw an error
Include what
Python update (new testing framework)
Approved!
Hi, I'm trying to get the correct solution for this kata, and when I try to use the inputs that are used in the "Tests" tab, I get same exact results using my code, in the IDE.
But, when I try to run the test here, I get the following error:
" Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 135168 bytes) in /workspace/default/_solution.php on line 7 "
Since I'm using the recursion for this kata, I guess I'm somehow running into the infinite loop, but shouldn't I get the same exact problem when running this code in my IDE? And also I think that infinite loop shouldn't happen in this case, because I've set the condition when to return the $signature array (more precisely $signature array should be returned when count of elements in array is same as the number of elements we've passed as argument to our function).
Thanks in advance!
Knowing the failing code would greatly help :)
This comment has been hidden.
Are you really, really sure the tests pass in your local IDE? Did you try all examples locally? "Sample tests" have these two examples which your solution is bound to fail:
Thank you! I must've deleted part of the statements that controlls these 2 test cases, and forgot to redefine it when I pasted the code in here.
It works now!
This comment has been hidden.
My python code works in VSCode. On Codewars I get an Exit Code: 137, Max Buffer Size Reached (1.5 MiB). Removing the print() used for debug did the trick.
so easy :)
yup !! But nice kata althougth
fun level :))
am i not allowed to use global keyword in python cuzmy code does run on my device but here doesn't
Read this: https://docs.codewars.com/training/troubleshooting#works-but-no
Hello everyone I ran into a problem: in the online compiler, js outputs everything as it should, but when I enter a solution, an error pops up, what is the problem?
Why do you have 2
tribonacci
functions?this is an accident, most likely I didn't see it when I erased the old solution and replaced it with a new one. But, in any case, even if I bring a new solution that seems to work in the JS online compiler, here it gives an error
Based on your code:
Now,
oldArray
is the first number of the given input.Meanwhile, you are writing this:
Hence,
undefined
because you cannot access indexing or positioning from a number literal, they are neither arrays nor strings.What does it mean to be "deeply equal" in javascript though?
It means 2 variables must have the same datatype and the same value when u compares them
One of my new favorite katas because of how satisfying the optimizations are. First I realized that I didn't have to check for an empty signature, and then I realized I could return my normal array even if the n was lower than 3, and now I'm trying to figure out how to avoid making an empty array then copying the signature into it which takes 2 lines. Very fun to work on this one!
in c# tests pass, but when I click attempt it gives me index out of bounds error, basically when index is 0 it says out of bounds for some reason
This could be because the random tests will give you an
n
value that is less than 3, meaning you can't expect the array to have all the elements you are likely expecting from it. For me I also had an issue where I couldn't copy the signature into a new array because signature was 3 elements and n could be less than that.Python I'm trying to test for n = 2 or 3 or 4 with the same lines like that for num in {1, 2, 3}.intersection({n}): return output.append(signature[num-1]) I expected return to be previous output (a list) appended with whatever number from signature indexed, but I'm getting 'None'. Why would list.append(int) return None?
The value of list is being re-assigned to the return value of list.append(), which is None. The append method modifies the list in-place and does not return a new value, so the value of list is changed to None. This is why None is printed as the output.
OP solved it, closing
File "tests.py", line 13 test.assert_equals(tribonacci([0.5, 0.5, 0.5], 30), [0.5, 0.5, 0.5, 1.5.5, 4.5, 8.5, 15.5, 28.5, 52.5, 96.5, 177.5, 326.5, 600.5, 1104.5, 2031.5, 3736.5, 6872.5, 12640.5, 2 23249.5, 42762.5, 78652.5, 144664.5, 266079.5, 489396.5, 900140.5, 1655616.5, 3045153.5, 5600910.5, 10301680.5]) ^ SyntaxError: invalid syntax
What the promlem with it? When I click "Test" that error, when 'Attempt', everything is fine..
When I try your code, I see no error like this. However some random tests fail, for example:
yeah. Reset my solution helped me. everything is okey.
This comment has been hidden.
However this is a problem with your code, and not a kata issue (= a bug). See there: https://docs.codewars.com/training/troubleshooting/
tests for JavaScript: ([3,2,1],10),[,6,93,2,1,16,31,56,103,190])
The test is this one:
D translation
Approved
Update to Scala 3
.
Could be just me and it's not a big issue but... I think there's an extra semicolon in the Rust sample tests. I removed it and reset the Kana but it's still there.
If you want to remove it you'll need to publish a fork of the kata with it removed which someone can then merge.
no problem. it was just a single character, so I removed it in the editor. glhf
why does ([1,1,1],1) = 1? Its easy enough to code but I'm not getting the maths behind it. I assumed ([1,1,1],1) = 1+1+1 = 3 ?
OK helps if I RTFQ: 'return the first n elements'. n = 1, so return first element only
Because the result list has only 1 value. [1]
More text, please
the problem said, it should return signature but why the heck they want [1] as return when actually [1,1,1] is given
That's not what it says:
With n = 1 you must return the first element of the signature.
it's not the best way to word the exercise, but yeah if
n < 3
, then the array to be returned should only have then
number of elements. If thesignature = [1,2,3]
andn = 2
, then the return should be[1,2]
This comment has been hidden.
Not a kata issue, that's a problem with your code. What if n < signature's length?
This comment has been hidden.
This comment has been hidden.
Yes, there is an infinite loop there. Not a kata issue, use
Question
label next time.Your code fails that test, figure out why.
Oops, I saw an error (thanks for the answer)
This comment has been hidden.
Your code worked fine for me, and please, mark your post as having spoiler content next time.
Yes. It works correct but it shows me that there are a mistake. Why?))
Which error? Please copy and paste it here. Have you tried clicking reset just in case you modified the sample tests without noticing?
Nice fun kata
My code Python is working fine for every test case except where n = 2, what i've understood from the description is that if n=2 and let signature = [a,b,c] so the program should return [a,b]. The problem is relevant for 16+ months.
Test for checking n=2 does not work correctly. elif n == 2: return signature[:2]
The tests are fine in Python. The control function does exactly that. There is a problem in your code:
Not a kata issue.
Very fun and ease introduction to dynamic programming
JavaScript folks-- slice or splice, and why?
You don't need any of both to solve the kata. If you don't know how it works, read the manual, it's all online. This is not related to the kata.
If you want to discuss a particular language feature, you'd better ask on CodeWar's Discord Javascript channel (see left panel).
I wanted to discuss this particular Kata, but clearly I had the wrong forum.
This comment has been hidden.
You are declaring a global variable so all preceding test cases' result will be stored in it which is wrong because the starting signature differs for each test case
This comment has been hidden.
not an issue, you're counting the index wrong or declaring wrong size for arrays.
here is my version of the solution, it works fine but after certain amount of numbers, arrays in general, cannot store. They have limited data which is exceeded. Try on your own.
public static double[] tribonacci(double[] s, int n) {
(my mistake)
This comment has been hidden.
COBOL translation.
approved
good one
This comment has been hidden.
Please mark your post as having spoiler content next time.
return
works, you forgot to also return the recursive call.I didn't even know. Everything is working now, thanks.
Only this kata doesn't work... Execution Timed Out Whole day i tried to attempt my solution but still the same
And with a total amount of submissions going soon to be 10k, how interesting that nobody never noticed that the kata does not work, uh?
This comment has been hidden.
Your code is incorrect. You're going into an infinite loop. Read here to get some ideas about how to sort that out.
it definitely is possible, i just submitted my code edit: and i regretted not refactoring my code before submitting
This comment has been hidden.
This comment has been hidden.
Most probably you did not test your code with inputs which cannot be handled by your solution. You tested it only with inputs which work.
Try calling your function a few times with cases from the sample test case. I just tried your code, and Nope! it is only able to pass few test cases before exceeding CW's Time Out limit
I believe this kata may have a bug, in the instructions it states "Signature will always contain 3 numbers", I was able to successfully pass every test except for these two: Expected: equal to [ 1, 2 ] Actual: [ 1, 2, 3 ] Expected: equal to [ 8, 7 ] Actual: [ 8, 7, 9 ]
is this an issue with the problem?
No, the signature always contains 3 numbers but you should return the first n elements of the sequence (signature included) with n >= 0.
If n is less than 3 you should return the first n sequence don't forget. For instance if the sequence is [a, b, c] and n is 2, you should return [a, b] or if n is 1, you should return [a]
This comment has been hidden.
You had already added the original
signature
array toresult
, but you did it again in hte corresponding loop whenn < 3
.Also, Your code fails for cases like
signature = [2, 0, 1]
andn = 2
. The expected result should be[2, 0]
but your code returns[2, 0, 1]
Read this instruction carefully -->
returns the first n elements - signature included of the so seeded sequence.
This was nice.
This comment has been hidden.
Please don't post solutions in Discourse. Check Solutions page once you've submitted your own to see all other solutions.
Don't post solutions in Discourse. You can comment submitted solutions, that's the purpose of the Solution page. And in any case, you must use a spoiler flag if you post code in a discussion or a comment. I put the spoiler flag for you this time.
Sorry! I won't do it again :)
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
About your question:
The list containing the first element of
[1,1,1]
is[1]
.This comment has been hidden.
See radhikabhat431's post below.
Your code is almost completely correct, but you are using
calloc
incorrectly. In the future, pleae post as aquestion
if you don't know what's wrong. Anissue
is reserved for when there is a clear problem with the kata itself.Sorry, i've never post something in this comment section. I'll post it with the correct label next time.
Out of bounds when test size was 1 or 0, is this a programmer error or am I thinking about it the wrong way? (I used arrays)
This comment has been hidden.
Your code fails for cases like
tribonacci([1, 1, 1], 1)
(your code returns[1, 1, 1]
whilst the correct output is[1]
)Thank you!
some time thay forget the most important thing in problem solving adding decent description and some example can any one know's why?
My code passes the intial test, but fails saying that it's out of range. When testing the same input in Visual Studio, it works properly and I don't get the error.
Hi. If it fails, it doesn't pass the tests. See if this can help: https://docs.codewars.com/training/troubleshooting/.
I cleared all the tests but while submitting I get the crash error. I guess the caller function(in C) is supposed to free the Dynamically allocated array which is returned in the function. I assume that is why test is crashed along with this error. 'mumap_chunk(): invalid pointer' Can someone help me? How to solve this error?
If your code crashes, it's a problem from your code and not a kata issue. Yes you have to allocate memory for your output, and the tests free the memory allocated for it. Maybe you should consider some edge cases that can cause problems. See if this can help you: https://docs.codewars.com/training/troubleshooting/.
Ran into an error "Max Buffer Size Reached (1.5 MiB)" I don't know the reason that caused this but I think the random tests were too large to handle that it ran into an error or something. Explanations are much appreciated
I had the same issue as well because I hade a couple of print statements in my code, when I removed those. It passed all the test and I was able to submit
I don't have print statements. Just return statements for the appropriate results. But thanks for sharing though!
Max buffer size reached is probably caused by what you print to the screen. It's hard to help without even knowing the language you're using.
I used python, and yea that's probably it but I don't know how to fix that
This comment has been hidden.
A problem with your code is not a kata issue, use question label next time. Your code is not returning for some values, print the input and figure out why.
I can't pass test on python. It works all fine, but last test with n = 425 fails. Comment: STDERR Max Buffer Size Reached (1.5 MiB)
Would be great if someone could share some thoughts, how to outplay this :)
Please read this: https://docs.codewars.com/training/troubleshooting#maxbuffer
Its a problem with your code, and not a kata issue.
Thank you, found a problem, passed the test :)
Okay just here to say that the "//hackonacci me" made my day.
This comment has been hidden.
when i click test it said pass and when i submit get error and it saying out bounce or length 0, in xbonnacii.
This comment has been hidden.
This comment has been hidden.
It is annoying that I can't pass because of this bug in Kotlin. Please fix it. It should work with random inputs too: arrays first differed at element [19]; expected:<532670.0267012811> but was:<532670.026701281>
While it certainly is clear that
532670.0267012811
is different from532670.026701281
, this is not enough to show why there is an issue with the kata. Please provide an example case including the input:signature
andn
, as well as the expected value and what your code returns.Thanks for pointing out that the problem lies in my code, not in the kata. My perspective changed and I worked out to pass the kata again. Now I have passed the kata, all the changed I need is something like from "m + n + o" to "m + (n + o)". I still think there is some wierd things happening in comparison of two numbers.
Now I remove the issue.
Hey, I do this kata in C and I think all thats failed with my code is the return value. This is the feedback: STDERR solution.c:22:9: warning: address of stack memory associated with local variable 'arr' returned [-Wreturn-stack-address] return arr;
But I don't know how to return my Array where my values lie on a different way. Please help
You can't return a local array, instead you must return a dynamically allocated
long long
array of results. I have added this comment to the solution declaration set-up. Best of luck!Nice kata! First time using divide and conquer or similar...
This comment has been hidden.
This comment has been hidden.
failing test in code wars but works in idle for case: test.assert_equals(tribonacci([1, 1, 1], 1), [1])
Already gave you the link to troubleshooting docs, please read them, we can't read your code if you don't post it.
This comment has been hidden.
A problem with your code is not a kata issue, also, we can't see your code, so there is nothing we can do, please, read this: https://docs.codewars.com/training/troubleshooting/
This is ridiculous. The solution is VERY easy. But somehow you have hidden expectancies. As we can't see what the basic tests are, I don't know what "I'm doing wrong". I 'll just skip this.
you can see tests if you need: https://docs.codewars.com/training/troubleshooting/#print-input
Can't understand why 4010 tests. My first solution also worked fine on my local computer, but here, all the cases in which n=2 don't, so had to right similar code in another way.
This was a great problem. I learned about the Fibonacci sequence a while back, but this put a fresh spin on it.
This comment has been hidden.
Do the provided tests rotate?
Answered my own question
This still doesn't work for Kotlin. Basic test Completed successfully, but random... expected:<956352.1708891367> but was:<956352.1708891368>
should be fixed.
This comment has been hidden.
OP solved it, closing
We do not need almost 4000 tests. I would suggest adding n = 1 and n = 2 tests into the basic tests so people can run into those edge cases in a more lenient environment.
My solution is "failing" a random test because the error of 3.725290298461914E-9 is less than the 1e-10 tolerance.
Ridiculous.
Pretty neat, but were 4000 tests really necessary? lol
To long to understand the problem..
This comment has been hidden.
This comment has been hidden.
Took some unnecessary extra steps here, still, nothing in intelectually more satisfactory than resolving a recursion problem.
Passing all tests but getting this error when I try to submit: "STDERR Max Buffer Size Reached (1.5 MiB)"
Solving with Python, please assist
Hi @jpchato, it's not an issue with the kata. Your code is outputting too much to the console, so just silence your print statements.
This comment has been hidden.
I submitted my code for Kotlin and failed the random tests. I see that a lot of other people have complained and the issue hasn't been fixed. At this point, I don't think the author is looking to fix the issue. I propose we remove Kotlin as a language for this Kata.
Everything works. I've finished this kata. Add
println
methods to figure out what was wrong with ur codeshould be fixed.
When I click on Test, it is passing all the tests. But when I click on Attempt, it is showing some errors. And the same code is working fine in my local editor. Please help me on this.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#when-i-run-tests-everything-passes-but-when-i-hit-attempt-tests-fail
This comment has been hidden.
I had the same issue. I was for 1 hour bussy what whend wrong
This comment has been hidden.
Not a kata issue. Use
Question
label next time.How many elements are you returning there?
my code is working fine for every test case except where n = 2, what i've understood from the description is that if n=2 and let signature = [a,b,c] so the program should return [a,b]. That's what my program is doing but it's wrong. Please someone correct me.
same here!
This comment has been hidden.
dont use while XD
C++: tests have warnings and does not compile, anyone else?
Tests indeed have warnings, but nonetheless they seem to compile and run correctly.
This comment has been hidden.
4000 tests seems excessive
Wondering if anyone can help my output matches the test output (written in python) but keeps being failes see below: Testing for signature: [145, 188, 33] and n: 1 Log [1, 4, 5] this is the results from my code via a print statement an outputted to codewars consule
It should work with random inputs too: [1, 4, 5] should equal [145]
Any new programmers here? Hope you add me.
P.S. my current language is JavaScript
This comment has been hidden.
You're confused there, signature always has 3 numbers:
n
can be less than 3.yes, that's what the instructions said, but somehow the tests performed should also pass with signature given as [],[1] and [1,2] otherwise there will be failed tests.
No, you have to return
n
numbers of the sequence, counting the ones of the signature too. So, the signature always has 3 elements, but ifn
is 0, you return an empty array/list, whenn
is 1, the first element of the signature, etc. I hope it is clearer now.Hello, tell me how do you validate an empty array in PHP? Because I can't do it with its different solutions:
Except if there is an error in the verification... Thanks in advance !
Facing some precision issue with random numbers. Is this Kotlin issue?
expected:<627093.059559724> but was:<627093.0595597238>
Same here
Same here signature [1.8190803733637595, 10.32113085317588, 2.4538921407466985] It should work with random inputs too: arrays first differed at element [25]; expected:<9145259.517695228> but was:<9145259.51769523>
signature [4.523989247754125, 4.4306407266327845, 2.9433070582317944] It should work with random inputs too: arrays first differed at element [21]; expected:<602130.3478075289> but was:<602130.3478075288>
signature [1.218691787383328, 7.628302847784772, 14.623238617452863] It should work with random inputs too: arrays first differed at element [20]; expected:<778388.1052085671> but was:<778388.105208567>
should be fixed.
not really a fan of the
n<3
case but I can see how that requires a more elegant solutionHi, general qestion - How can I see exact results of my program execution, and not just failed check reports?
Printing before returning?
That wiil help, thank you.
It's a trap!
Kata says: "Signature will always contain 3 numbers"
Testing have signatures with even ONE number.
State the language you're trying. I've checked Python and Ruby (the 2 languages you've trained so far) and in neither of them that happens, the signature always has 3 numbers:
The output can be an empty list/array or have 1 or more elements depending of the value of
n
.Thanks for your reply.
I am using python.
Here's a screen capture of what happened: https://pasteboard.co/JsmxT8r.png
The screenshot is about the output, not the input of your code.
It literally mentions above that it's testing signature of 3 elements...
Thanks. I did not took notice of the cut message from the screenshot.
Python: Hi guys, although I have managed to get all the tests correct on my attempt, it doesn't let me pass the kata, all I know is that it is giving me an exit code of 137. Any help would be appreciated. Very new to codewars
To anyone else having this problem, just figured it out. I removed all of the print statements that I was using for basic debugging and that did the trick.
My code seems to pass all tests, but it crashes at some cases:
Test Crashed Caught unexpected signal: 6
Everytime I attemp it crashes at another case, it seems to be random. Any ideas?
Your solution crashing is not a kata issue, you need to fix your solution.
Check if this section of FAQ is helpful: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#appendix-a-exit-codes-signals-and-other-strange-numbers
Still a Kotlin rounding Problem:
It should work with random inputs too: arrays first differed at element [20]; expected:<765394.1346170895> but was:<765394.1346170896>
should be fixed.
This comment has been hidden.
read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
;)
This comment has been hidden.
I think need to add in test section test that show what resoult should be if there's a input data like this: [1] , [1,1]. And better,but in this case Kata will be harder and longer, add what resoult should be on incorrect input data. Or create a new Kata with this tasks.
After 63k completions nobody is going to change it. It would be unfair and would render all solutions invalid.
Besides python test cases are locked.
(not to everyone... ;p )
I agree with an earlier poster. If you have cases where signature is somthing like [1,1], it is FALSE to claim that "signature is guaranteed to have at least 3 numbers." If you ask me to choose between believing that "guarantee" and my own lying eyes regarding the case of [1,1], I'm going to believe my own lying eyes and assert that [1, 1] has (at most!) two numbers. PLEASE accurately describe the rules on the input.
Che stupido sono io...Please disregard my post. Jeez what an idiot I can be sometimes. Sorry Giacomo...
Ah, that unexpected language (native speaker?); worry not, we all make mistakes (I do plenty) and being able to admit them is certainly a solider base than trying to never err :)
Native speaker of English (not Italian :))
has bug in kotlin "It should work with random inputs too: arrays first differed at element [19]; expected:<684179.8255011056> but was:<684179.8255011055>"
Have the same bug. Seems to be a bigger problem, as the issue is mentioned already from way before if you scroll further down.
I was trying to do this one in Go.
When I attempt to send in the result i get some random tests that fail. For example, this one:
Tribonacci([3]float64{15, 7, 10}, 3)
Gives:
Expected <[]float64 | len:0, cap:0>: nil to equal <[]float64 | len:3, cap:4>: [15, 7, 10]
This is really confusing to me.
almost all my test passed however in the test Test.assert_equals(tribonacci([1, 1, 1], 1), [1]) failed is someone has the same issue any insigt would be aprecciate
what is the logic behind this particular test?
It's pretty basic. First element (n = 1) of signature [1, 1, 1, ...] is [1], not [1, 1, 1].
This comment has been hidden.
thks
This comment has been hidden.
Please, don't post solutions in discourse.
This comment has been hidden.
watch the stack trace..
A bit unclear conditions in test examples. What output should be, if input ([0, 0, 1], 1) - [] or [1]? And what if n = 2?
For your input
([0, 0, 1], 1)
:[0]
and if n was 2,[0, 0]
This comment has been hidden.
When n is 1, you have to return the first element of the signature.
I understand now, thanks!
I believe this kata has bugs in C. If I do nothing but return null I get 8 pages of errors starting with (note error is in fixture.c):
fixture.c:24:29: warning: passing 'const long long *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] ASSERT_ARR_EQ(expected, submitted, n); ^~~~~~~~~ fixture.c:7:14: note: expanded from macro 'ASSERT_ARR_EQ' { free(submitted); submitted = NULL;
^~~~~~~~~ /usr/include/stdlib.h:563:25: note: passing argument to parameter '__ptr' here extern void free (void *__ptr) THROW; ^ fixture.c:24:5: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat] ASSERT_ARR_EQ(expected, submitted, n); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fixture.c:13:17: note: expanded from macro 'ASSERT_ARR_EQ' i, submitted[i], expected[i]);
^ /usr/include/criterion/internal/assert.h:529:62: note: expanded from macro 'cr_assert' #define cr_assert(...) CR_EXPAND(cr_assert(VA_ARGS)) ^~~~~~~~~~~ /usr/include/criterion/internal/assert.h:159:28: note: expanded from macro 'cr_assert' CR_VA_TAIL(VA_ARGS)
^~~~~~~~~~~ note: (skipping 31 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) /usr/include/criterion/internal/preprocess.h:35:43: note: expanded from macro 'CR_EXPAND' #define CR_EXPAND(x) x ^
You mean compilation warnings ? Other than a shitton of warnings, kata works fine in C.
Ah yes, Correct.
I guess my mind set is warings == errors
I don't let warnings stand because they either contain important info or obscure other important info when out of hand...
Actually when I simply return NULL there does appear to be a testing error:
Test Results: Sample_Tests should_pass_all_the_tests_provided Test Crashed Caught unexpected signal: SIGSEGV (11). Invalid memory access.
Should the Test crash?
NULL is supposed to mean 'empty array' in this test. Shouldn't it be reported as a wrong return value as opposed to the test crashing?
If you look at the test code:
#define ASSERT_ARR_EQ(expected, submitted, sz)
if(sz == 0 && submitted != NULL)
{ free(submitted); submitted = NULL;
cr_assert(0, "n == 0, should return NULL\n"); }
for(size_t i=0; i<sz; i++)
if(submitted[i] != expected[i])
cr_assert(0,
"Incorrect value at index %i: %lld should equal %lld\n",
i, submitted[i], expected[i]);
cr_assert(1);
It does not NULL check submitted if sz != 0...
Minor issue since as you pointed out you can still do the Kata...
This translation was done when I had just started translating to C. I can't recall if
C18
was available then or only3.6
. When I became aware ofC18
I began translating with that as my standard. So, seeing what's up with this kata suggests I go check out my other old translations as I have with this one. Today I gave this translation the royal treatment: by adding theNULL
check you mentioned, providing better feedback for failed code, and (of course) eliminating all of those 32 warnings.Assume! That sounds reall good.
I'm very impressed with your turn around time and dedication!
Why aren't the best solutions using recursion? Isn't better to solve this problem with recursion?
This comment has been hidden.
Are you sure about that? Which language?
Python there is one test that tests for sequence of size 0 that should be [] as the wording of the question says and the test asserts wrong if you return [] it happens it expects [1].
No, the log appears above the test result, you're confusing the input of one test with the error message of another. Both tests expecting
[1]
and[]
are ok.This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Not a kata issue, your code is missing some import. Next time mark your post as having spoiler content please.
I ommited the class declaration and imports. They're there. If they weren't, Eclipse wouldn't have passed the unit tests, but like I said, it did. I only included the method, as I thought people would be able to realise... :/ Also, I did mark it as a spoiler, but then I edited it, and I must have forgotten to turn it back on. That one is my bad...
If somebody else could copy and paste into the Kata to check my method, and my sanity, that would be greatly appreciated You will need the import: import java.util.*; (Not the best practice, but it will work ;P)
Your code is not handling that right, and there is another problem too, test your code with values of n < 3.
That is not what I am saying in the op! The code WORKS! I wrote it in a separate IDE (Eclipse) and ran it against the provided unit tests. The unit tests all passed. Yet, when pasted into the online editor, I get a stack overflow error, instead of the correct result. Does codewars provide a smaller amount of heap than a standard compiler? Because then the large numbers of stack frames may cause it to throw the stack overflow exception? All though my other recursive solutions do not behave in this way... :/
I've copied and pasted your code and it only worked after handling the cases I told you, have you tried your code with those values? You used recursion and if n is less than 3 your recursion never ends (that's the stack overflow error about). It's not a problem of environment, it's a problem with your code's logic.
N will never be less than 3, by definition of the problem, therefore handling those cases is outside of the scope of the kata. And it doesn't matter that I implemented my solution slightly differently than suggested, it's only the result that matters, and the correct results are produced, as shown using the separate IDE.
Please, read the description again:
And print the input if you don't believe me. N is any integer equal or above 0, the instructions say this clearly, your code is wrong (here or in your IDE for n < 3).
Ok yes, in the randomised tests, 0 <= n < 3. I will admit that my approach does not work for those tests. But it is still failing on the basic tests, which I have done separately, and have confirmed to work. (n==3) And there are still randomised tests where n > 2, yet still fail... How are the stack overflows being caused in these cases?
No idea, as I said, once I modified your code to handle cases < 3 it worked for me. Why don't you do that and paste your current code?
P.D.: in basic tests there are tests with n < 3 too. And there is no test with n == 3 there.
I haven't made any modifications past what I have already provided, so that is my current code. I could do that, and it would probably work, but that doesn't solve the issue that we can't seem to solve :/
I misread. All of the basic tests are n==10, not 3 and therefore should not get caught in the infinite recursion part of my program, and therefore should work.
The fact that the basic tests work offline, but then fail online, with exactly the same code is the part that is my issue. Yes changing the code will fix it, but the code I have already provided doesn't seem like it should be behaving this way... Would it be possible to get this marked as not resolved, and then if anyone provides an answer at a later date that explains this strange behaviour, it can be marked as resolved?
No, because it's a problem with your code, not with the kata:
The basic tests that don't work here, won't work in your IDE either (because your code can't handle them), maybe you're confusing the logs or something.
Here are the tests:
assertArrayEquals(new double []{1,1,1,3,5,9,17,31,57,105}, variabonacci.tribonacci(new double []{1,1,1},10), precision); assertArrayEquals(new double []{0,0,1,1,2,4,7,13,24,44}, variabonacci.tribonacci(new double []{0,0,1},10), precision); assertArrayEquals(new double []{0,1,1,2,4,7,13,24,44,81}, variabonacci.tribonacci(new double []{0,1,1},10), precision);
You can see the parameters where n==10.
Those 3 are the sample tests and always worked with your code with the import. When you click attempt, there are more tests than only those 3 in the basicTests, that's why I told you to print the input.
Can confirm it is JUnit from Eclipse that is telling me that the Basic Tests are working
I am aware that the three basic tests work with my code, however the tests do not pass within the online environment
Properly solve the kata or forfeit it, see the testing suite, realize the basicTests in the sample tests are one thing and the basicTests on Attempt are different (already told you this). I feel like talking to a wall here, seriously.
(May need to right-click -> open in new tab)
I am not concerned with the randomised testing! There is a discrepency between real test results, and the results given by codewars, even though the code, and the tests are the same, as evidenced. (Eclipse unit tests pass, codewars unit tests fail. Same code. Same tests.)
This comment has been hidden.
This comment has been hidden.
Ty for putting up with me =P
Congratz, and next time, please take the advice at the second post, I'm tired now ;)
Just to make it clearer, I renamed the test in Sample test to sampleTests.
This task have a broken cases with signature. Why i should be take {12, 0, 17}" and return empty array or when i take "{1, 1, 1}" and return 1. I should be return only Sequence not a single value.
What does exit code: 139 mean ?
I canno't post my result due to:
Also, I get the Exit Code: 139, I would like to mention that I've checked my code, and I don't have any memory violation.
These are just warnings, they don't cause a 139 exit code, and clearly, it's segfaulting somewhere. Anyway, not a kata issue.
"But what if we started with [0, 0, 1] as a signature? As starting with [0, 1] instead of [1, 1] basically shifts the common Fibonacci sequence by once place, you may be tempted to think that we would get the same sequence shifted by 2 places, but that is not the case and we would get: ..."
This is a bit wrong here. The fibonacci sequence becoms a sequence of 0's when "shifted" by 2 places, since by definition, the sequence adds the previous two numbers, not previous three.
Shifting sequence by 2 places gives us:
1: 0 2: 0 3: (1) + (2) = 0 + 0 = 0 4: 0 5: ...
I feel like an edit of the description is necessary.
it's not fibonacci, it's TRIbonacci. The description is fine, you just didn't grasp what the task is yet.
I understood that it was referring to a new concept, but yeah, I also misunderstood the task.
[Groovy] I think that exemplary solution has a mistake (variable memory overflow). Look at the negative numbers in the returned sol's array.
This comment has been hidden.
if n == 0
inside thewhile
loop, you could just put that first.break
statement after thereturn []
statement is never reached, so it's pointless.while
loop on two tests, and you could use some print statements to find out whichGroovy sample tests are the "Example" tests. :)
Oops, I forgot sample tests. Fixed.
Description says "Signature will always contain 3 numbers". But some tests has 1 or 2 values. Please, fix description/tests.
what language?
Sorry, forgot to mention - c#
I just solved it and it's always 3 numbers. Please fix your code =/
@Syyno ~ Not sure how you arrived at that, because your code would crash if the length of the signature was less than 3.
Hi, i solved with recursion. But then noticed all the highest rated solutions use iteration instead. I know recursion isn't as efficient, but i do like it.
Is iteration so much more efficient that for this problem recursion is a bad solution? Are the differences that dramatic?
This comment has been hidden.
you have to dynamically allocate memory
This comment has been hidden.
this would be plenty to know what's going on:
*** Error in './test': munmap_chunk(): invalid pointer: 0x00007fff4ec8c690 ***
you need to return an integer array. in C this means the function author (
you
) needs to dynamically allocate memory for the array. the caller of the function (me
) will free the memory.This comment has been hidden.
this allocation works, but your code tries to write beyond it
Thank you dear friend i finally got through it !
excellent!
I'm working it in C... There are so many pointers and "unpacking" to test my result. I can't figure out how the Kata is requesting my returned result (I'm using *result).
I also get errors thrown that I'm not sure what they correlate too. I put my code in Xcode and I'm getting the correct answers... I feel like I'm more fighting the Kata test than I am figuring out the problem/challenge and learning C. Maybe figuring out the test functions is part of the test?
well, Xcode is not Codewars. you're always going to have to rely on what results you get here, not elsewhere. the first part of the declaration of the kata
long long *tribonacci(
shows you what your return type needs to be, namely along long
array. what this means for a C coder is that you are required to dynamically allocate memory for the returned array. (many of your errors are probably related to memory management) so work on that. good luck!Dart, Factor, Groovy, Julia, R, Racket, and TypeScript translations.
kotlin translation of the kata doesn't handle floating point comparisons well too.
Any chance someone could have a look at it?
should be fixed.
This comment has been hidden.
looks like a memory issue. post your code with a spoiler tag and I'll take a look for you
This comment has been hidden.
okay, so you can't return a local array such as
long long results[n]
, you have to create and return a dynamically allocated array... plus I can tell you there is one more small detail you missed from the description, good luck!!!!
@rowcased: I flagged your comment as spoiler just in case.
Well now I cant read it so thats not very helpful
@Steffan153, if the ALowVerus forgot a spoiler tag for their code comment, I get that. But for my response comment I don't see a problem in helping with a basic C coding thing as I haven't given anything away on how to solve this particular kata.
Well, since I'm not an expert in C, I flagged it just to be sure. @ALow: Unflagged so you seee it.
Not easy, but very well
This comment has been hidden.
Not a function and you are not returning a thing.
This comment has been hidden.
Your function still isn't returning the result, and it doesn't pass the sample tests.
I like this Kata, however, there is one point that was rather confusing. It is stated that the function/method has to return an array "of the first n elements - signature included" of the parameter array s. Plus, it is guaranteed that the signature always contains 3 values. So how come that there are tests that expect arrays of length less than 3 (e.g. 1) as a return? It would be nice, if some one could clarify that for me.
I was confused by the same thing. It could be more clear that the "n" is for the first "n" number(s) of the sequence - in an array.
But this has nothing to do with "it is GUARANTEED that the signature contains 3 values". It's distressing and unfair that the solver, counting on this guarantee, is assaulted with INCORRECT results because some of thie inputs DO NOT HAVE 3 values.
"Distressing" or even "assaulted", plenty of uppercase, not admitting you might be wrong...
I would take a wild guess and assume you might not be too far from a uni, possibly an anglosaxon one.
Not sure about your language, but the initial signature is always 3 elements, so, unless you modify it, think again at what might happen.
This comment has been hidden.
onelist
is not a list there, and check how to use markdown formatting, reading Python code without it, where tabulation does matter, is very difficult.'Looks like you've solved it'
This comment has been hidden.
solution=signature
doesn't create a copy, it's a new reference to the same list. So, when you mutate solution, you're also mutating signature.Thank you for your clarification!
Solved then.
I get this error: Response received but no data was written to STDOUT or STDERR. What does it mean? What do I need to do? My language is Python.
Not an issue, a question (see below).
This kind of error happens when you saturate the RAM allocated to the runner that executes your code. Meaning either your code isn't efficient enough (memory wisely speaking), or you got somewhere an infinite loop accumulating data in some cases.
FYI, here is the terminology used on cw (and some more info, just in case... And because it's faster than to suppress some parts of the original message... x) ):
Issue
: problem in the kata itself (description, wrong tests, wrong internal solution...)Suggestions
: well, I guess that part is clearQuestion
anything else that is related to you having a problem solving a kata -> that's you, currently.When you post issues:
When you post a question: well, most of the above apply too x)
When you post code, use proper github markdown, so that it's readable.
cheers
@Giacomo: there are a lot of issues opened here... :o Couldn't you take a look and handle them?
Hi, I am new to C programming. Does anyone tend to get this error : "Incorrect value at index 0: 1 should equal 1" or even "Incorrect value at index 0: 18 should equal 18". How do i fix this?
there was an incorrect printf specifier which has since been fixed
I got scared at the beginning and lost some honor.... I came back and nailed it! Don't let this kata scare you by its name, it is totally doable.
Pretty sure one does not lose honour for just postponing a kata.
The losing honor must have been related to something else (e.g. comment downvoted), as you don't lose honor for postponing a kata.
Thank you guys, I didn't know that. By ay chance, do you know if there is a way to drill down the causes of why my honor got downgraded? Thank you!
I believe you get more info only as a paying user; being downvoted is the most likely source of negative honour.
doesn't seem to be the case, tho.
@jsalinasf: how much did you loose? if it's one or 2 points, might be a satisfaction vote (after you completed a kata) that has been removed accidentally (sometimes, when you click at the wong place in the page, that can remove your vote). If more, might be worth of reporting on the github repo.
@Blind4Basics I lost like 4 to 6 points (not exactly sure). Maybe I was downvoted somewhere as @GiacomoSorbi told me. I'll be paying attention to my honor metric and if somethig weird happens again I'll certanily open a report on the github repo. Thank you everyone!
System.IndexOutOfRangeException : Index was outside the bounds of the array. i'm in c#
same, tried my method in VS and seems to be working fine.
Thank you for the fun exercise! Rust translation of the kata doesn't handle floating point comparisons well. Usually, with the tests that include floating numbers, it is common to specify the precision with which they should be compared. However, I cannot see what this kata has to do with floating numbers. They don't add any value in comparison to integers, only technical problems.
Feel free to pass me a fix for that kata.
This comment has been hidden.
Can you submit a Rust translation or at least check the code, now that you can see it all once you solved it?
I'm getting Response received but no data was written to STDOUT or STDERR. I tried the examples on the Python IDLE, and they worked just fine, but for some reason it's not working here.
Almost 13k people solved it in Python, so I would be moderately confident the problem might be in your code.
how do i know if my solution attempt was succesful? I don't get compilation erros but I also have no clue if i did it correctly. I get exit code 139 and thats is literally it. Now I'm here and it says Train again or next Kata ....did i win????? what
It means you passed some test, while others made your code crash.
Yeah that really doesn't help me at all. Theres obviously something wrong with my code syntactically but how am I supposed to figure that out without looking at solutions. I don't get why we aren't allowed to view them.
You can't view solutions of katas more than one level above yours, so either debug your code step by step and figure it out yourself what's wrong with it, ask for help showing your code and marking your post as having spoiler content, or solve more katas until you reach 7kyu and then you can forfeit this one.
This comment has been hidden.
Read how to use markdown formatting so some things don't dissapear from your code when pasted here. I don't know C++ myself very well, but I'd check two things if I were you:
Good luck with that.
Thanks for being so helpful. I think people like you really make huge impacts in others lives. Initial barriers may not be big but they have long term effects so i really appreciate it. I was able to figure it out and the solutions was excactly along those lines. I also didn't know there was markdown support here so thanks for the tip.
My code passes fixed tests, but when random test takes place, the test crashes with following error:
Error in ./test: corrupted size vs. prev_size: 0x000000000138a070\
.Sometimes I would get another error:
Error in ./test: free(): invalid next size (normal): 0x00000000012550a0
.Language?
these are C errors; the user (now gone), was incorrectly managing memory, issue closed, saluti
Couldn't figure out what I was doing wrong. I think I was trying to free the array and it didn't work.
aha, well in cases like this, (such as virtually every C kata on this site), you return the result(s) and the caller of the function (not you) is responsible for freeing any allocated results that are directly, if need be. you may allocate something extra within the function, but then anything not returned is your responsibility to free.
I'll have to think more on this. Thank you.
you're welcome, let me know if you have any other question later, happy coding!
This comment has been hidden.
that means you're storing too much data in memory. You need to change your approach a bit to make it "memory wise"wait, forget that. I forgot you needed to return the complete sequence. No idea for now.
ok, that's actually it, but because of sort of an "edge case". Print stuff inside your loop, so that you'll hit the buffer limit before anything else (print enough, tho), that should allow you to track what you forgot.
Thank you, I got it working.
Not sure what the assertion logic is doing when I submit my solution for Kotlin. My last print statement before i return the DoubleArray is:
Result: [1.2219787059623188, 7.958071682121853, 10.172098571448887, 19.35214895953306, 37.4823192131038, 67.00656674408575, 123.8410349167226, 228.32992087391216, 419.17752253472054, 771.3484783253552, 1418.855921733988, 2609.381922594064, 4799.5863226534075, 8827.82416698146, 16236.792412228931]
then I get an error:It should work with random inputs too: arrays first differed at element [0]; expected:<1.2219787059623188> but was:<2609.381922594064>
But as seen from the println, the first element is1.2219787059623188
and only the twelfth element is2609.381922594064
I have the same problem in Kotlin and I was so proud of my solution too :( the order of assertion logic seems to be mixed up for kotlin.
Can you pass me a fix, possibly opening a translation?
Kotlin's tests were subject to input mutation troubles, and expected/actual where swapped in the random tests.
Handled. Hopefully that will be enough.
This comment has been hidden.
This comment has been hidden.
You are modifying the input array: do
l = sig[:]
instead.Still getting same message
For what input?
for test cases and it also show exit code:137
Again: for what specific input? Print it, if you do not know.
"Signature will always contain 3 numbers" This is a lie. Why would you state this and then use inputs that do not in fact contain 3 numbers? And on top of that the instruction do not specify what needs to be returned if the array is less than 3.
A bit less drama and a few more info about the language, the test cases, etc?
Just tried the C# version. Sample tests pass. Basic test failed (index out of range). Random tests passed. Copied my code into VS and it runs fine for my tests. Why index out of range? I didn't experience any issues with rounding. All the random tests worked fine.
Commented on the wrong spot, sorry. Not sure how to remove comments on here.
Facing exactly the same issue as JMrbl. Every time expected result is slightly different from my output. Seems like the problem with precision. Does anyone have any idea how to fix it?
Example output: It should work with random inputs too: arrays first differed at element [33]; expected:<3.8325466338498983E9> but was:<3.832546633849898E9>
Kotlin
@Giacomo: keep this one opened: my fix won't handle that part (the most surprising part is that nobody seems to have the same problem with java while it should have the exact same behavior than kotlin... :/ )
Any chance we could get that thing fixed? It unables submitting the solution for this kata.
The same is happening to me :'(
I'm having the same issue with rounding.
should be fixed.
I also have the same problem in java
This comment has been hidden.
because you initialized
sum
as an integer ... where you needed to return a dynamically allocated long long int arrayThe description is not clear especially for those who speak English as second language !
Well, English is my 3rd/4th language: suggestions?
This comment has been hidden.
This comment has been hidden.
returning NULL in place of an empty array when n == 0 is correct . . . but I don't see how you're even passing the ninth SAMPLE test if you're not allocating memory for ALL cases where n > 0, such as you are with n == 1 and n == 2. try that.
.
Solved! Thank you!
What can we do there? xD
"It should work with random inputs too: arrays first differed at element [20]; expected:<831540.5337225463> but was:<831540.5337225464>"
Kotlin
closing here: opened somewhere else in the page.
This comment has been hidden.
Your return statement is at the wrong place ;-)
I have tried putting it outside the while loop it still doesn't work:(
Your while statement isnt behaving as you think. As soon as it enters the while loop it returns 's'. The code following it never executes. return breaks any loop or code execution and will return the value, in this case 's'. It always returns the first three elements because you return the first three elements before any operation in conducted. Furthermore, you should consider completing operations on the list and not loading it into separate variables(n1, n2 n3). From a memory standpoint this is inefficient and IMO is messier than just completing operations on the list itself. These operations can be done on the passed in list itself.
In kotlin I see the following error "src/test/kotlin/fixture.kt:10:84: error: unresolved reference: Solution" after running any kind of test.
Put
tribonacci
insideobject Solution {}
like how the initial code was. I think it's unnecessary and I don't think it's a best practice, but current Kotlin translation of this kata expects that.I might change it later for this reason, but this is why you're getting that error.
Changed
This comment has been hidden.
Thank you so much for the information in your edit, after swapping around the order of additions I passed all the test cases too. Shouldn't the second way (v[i-3] + v[i-2] + v[i-1]) be more precise too, since the smaller numbers are added together first, causing less rounding error?
This comment has been hidden.
Done, thanks :)
Why list instead of tuple for signature?
@Unnamed The output must be list and i want to input signature be same type as output
This is logical in a way, but I think languages have strict static typing for a reason: for example, destructuring such a signature requires handling of signatures of lengths other than 3 for the pattern match to be exhaustive.
Agree that signature fit to be tuple. I agree that for bigger structures it might have bad performance, but in 3 items i think it's unnoticeable. For me good argument to be tuple is when you try to use it for for example four or two items, compiler warn that its bad use. My only one arguemnt is what i said (same type as output), and maybe easier to understend for begginners. You start to convince me, if you think that much better is tuple i can change it.
@kzm
The description has
It's always 3 numbers so we should use
(float, float, float)
. Otherwise, we need unnecessary pattern match for a list like @Unnamed mentioned.Can you update it?
I tried to change it, when click run - all test pass (test cases and sample test cases), but when i click publish i have warning (at bottom of page) that "it was publish with failed tests", but it wasen't publish. I don't know is it a codewars bug or mine ?? If you want i can past here updated code and tests.
@kzm I don't know what's causing the error you saw, but you need to fork your original translation and publish that.
I'll try forking your edited translation and see if that works.
@kzm can you try forking (and publishing) your translation?
@kazk I created fork: https://www.codewars.com/kumite/5c684900df403c3cea71cf5a?sel=5c6c4c7cdf403c6fbb71ce1d Need to aproove
Done.
Sorry I haven't noticed until now.
In C
NULL
is expected instead of an empty array and this case isn't tested at all.@Unnamed
C translation with NULL return check for n==0
It says, "if n == 0, then return an empty array", not NULL.
C translation with adjusted description
Approved.
I have no idea why it's adding a strange requirement to the description instead of just fixing the translation, but OK.
Rust has a better type system, so the type of
signature
should be&[f64; 3]
.Not fixed either.
Can you open/fork a translation with the fix?
The tests from this translation seem to work correctly: https://www.codewars.com/kumite/5c6195d95a40bc20db9ecd56?sel=5c6bc159f1ed751df12981b1 Either something happenned during approval or it was edited afterwards, so just copypasting the code should be enough.
Ok, tests updated - what about now?
The tests look good now, but the initial solution should be updated too.
Ok, done.
Floats again... This time Rust:
I've tried to fix this issue and to change type of
signature
, but CodeWars shows that "Kumite was published with failed tests!". All tests seems to pass though. What does it mean?I'm not sure, it looks good. It may be related to the fact that the translation has been approved already. You need to create a fork for the updates to be appliable by approval or the changes can be just copy-pasted into the kata.
Not fixed:
@GiacomoSorbi
Rust translation
I am newbie here so I hope you'll help me if I'm doing something wrong
I guess it is fine enough to get approved; stay around if people complain, though ;)
Fork and open a new translation with the fixed.
@GiacomoSorbi Well, I don't realize how to fork Kata. Maybe I have broken something trying to fork. Do I need to solve it in original language to fork? BTW how to find out which one is original language and which are translations? Wiki is not so much helping in understading Codewars interface.
There should be a Fork button at the translation page. Create a fork, resolve conflicts in the description if any or add an empty line or something if there's nothing to change, publish.
I've finally found the button. Feeling a little stupid. Should I approve fork or just give you link to it?
Fork
Approved.
C:
C pure int translation
@GiacomoSorbi
Unnamed had a look at this. Should be fine. Thanks for your patience!
No worries, we all do mistakes; approved :)
More errors above...
@GiacomoSorbi
I haven't been seeing notifications from replies... Question: as I just did with your name, does typing "@" affront the code_warrior_name guarantee a notification?
Regardless, sorry for just getting back to this. I happened to find a missed message on a different kata so I checked them all.
I made a fork that uses the proper NULL check available to Unnamed in his ISSUE message (see above).
"@" doesn't do anything. Notifications appear for replies to your comments and for comments to the katas you've commented in the last week.
Unnamed is correct; translation approved now :+1:
In Kotlin I can succesfully pass all sample tests, but I get into issues with rounding when running random tests. Can anyone explain what is the rounding rule used in this Kata?
Same problem in Rust.
this is handled for Kotlin. Other issues opened about Rust, so closing.
in plain C incorrect value at index 13: 64548.1 should equal 64548.1 incorrect value at index 4: 85.4 should equal 85.4 and so on
yeah, I was made aware of the issue, but I had been awaiting a response in relation to it.
@GiacomoSorbi
I will have this done today
Approved.
What do you mean? incorrect value at index 32: 1.658171e+09 should equal 1.658171e+09 incorrect value at index 26: 3.309595e+07 should equal 3.309595e+07
Does every translation have to use that stupid
float
now? At least there should be proper comparisons. C:current saved C translation
My apologies, especially concerning improper comparision. I created random float tests because there was at least one in the given fixed tests. If you feel I overstepped by adding this to the kata, I could set the random tests to integer values only. Alternately, please check my changes to the float assertion... these changes were saved, but I don't know if they'll will register, because after the edits I clicked publish and there was a 'failed tests' message, so no publish. If I have to fork it to make them work, let me know. Or, on your advice, in that step I will revert the random tests as mentioned. Thank you.
So, final decision?
C translation with floats removed from random testing
@GiacomoSorbi
Done.