You are returning a numpy array, but the tests expect you to return a list of lists. They are different data-types and they work differently. The tests are basically comparing your return value to some expected value like this: your_answer == expected_answer, and if that expression results in True, you pass the test. When you compare two lists like list1 == list2, you get a single boolean such as True once the expression is evaluated. When you compare a numpy array with something like numpyArray == list, the result of that expression is another numpy array filled with booleans like this: [True, False, False]. The tests aren't expecting this, and that's what causes the error.
That method is not available in numpy version 1.24, which is the version that codewars currently uses. You could request a module update on github, but that will likely take a long time. Realistically, you just need to find another way to solve the kata. Your solution can work with minimal changes if you examine the documentation that you linked more closely.
The meaning of "consecutive" is explained in the description: "By not consecutive we mean not exactly 1 larger than the previous element of the array." So basically numbers which differ by more than one are not consecutive. In the example [4,6,7,8,9,11] the 6 is not consecutive, because it does not come (as a natural number) after 4.
as I understand it, the logic of the consecutiveness is defined by the first two entries....
(and therefore the first two entries can never be the answer...)
This comment is hidden because it contains spoiler information about the solution
In Javascript, Node 18 is enabled, but tests don't use chai, causing a deprecation warning on test and attempt.
You are returning a numpy array, but the tests expect you to return a list of lists. They are different data-types and they work differently. The tests are basically comparing your return value to some expected value like this:
your_answer == expected_answer
, and if that expression results inTrue
, you pass the test. When you compare two lists likelist1 == list2
, you get a single boolean such asTrue
once the expression is evaluated. When you compare a numpy array with something likenumpyArray == list
, the result of that expression is another numpy array filled with booleans like this:[True, False, False]
. The tests aren't expecting this, and that's what causes the error.So, you need to not return a numpy array.
This comment is hidden because it contains spoiler information about the solution
great. THX for this variant.
from functools import reduce
THX for your quick reply!
Ok, that helps a bit.
Another solution already completed
THX again
That method is not available in numpy version 1.24, which is the version that codewars currently uses. You could request a module update on github, but that will likely take a long time. Realistically, you just need to find another way to solve the kata. Your solution can work with minimal changes if you examine the documentation that you linked more closely.
This comment is hidden because it contains spoiler information about the solution
oh
so I choose the exact opposite interpretation.....
thx for your patience,
the "new" interpretation makes it a bit easier ;)
The meaning of "consecutive" is explained in the description: "By not consecutive we mean not exactly 1 larger than the previous element of the array." So basically numbers which differ by more than one are not consecutive. In the example
[4,6,7,8,9,11]
the6
is not consecutive, because it does not come (as a natural number) after 4.hm, thx for the rply at first.
as I understand it, the logic of the consecutiveness is defined by the first two entries....
(and therefore the first two entries can never be the answer...)
... am I wrong?
Did you test your solution with examples? Did you try this test case?
test.assert_equals(first_non_consecutive([4,6,7,8,9,11]), 6)
Your solution has a bug and fails when the answer is on position
1
, for example[0, 2, 3]
. You need to fix it.This comment is hidden because it contains spoiler information about the solution