Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This kata is a duplicate of https://www.codewars.com/kata/60df63c6ce1e7b0023d4af5c
No, it is that the reference solution is consistently wrong when
s == l[0]
andlen(l) > 1
. For example:The kata has performance requirements, so it should specify input range.
Good question. I'll look into it.
I'm seeing a bug in the random tests, here's an example:
With these inputs:
l = [3, -1, 1, -8, -6, 10, 3, 0, -7, 0]
, ands = 3
.I find these four solutions all summing to
3
:sum(l[0:1]) => sum([3]) => 3
sum(l[0:3]) => sum([3, -1, 1]) => 3
sum(l[6:7]) => sum([3]) => 3
sum(l[6:8]) => sum([3, 0]) => 3
The error message says I should be finding 3 not 4 solutions, are solutions that end in zero excluded from the count?
updated as above.
I went with your original premise and updated the description with a hint: somestring.count('')
So in the test cases, there is now:
I think I see what you are saying. If we say that sub-arrays must have length > 0 then
would be 0 instead of 1, which is mathematically incorrect
I don't like the idea of removing s = 0, though - that seems even more "special", requiring a special line of code (in solutions and tests) rather than a change in algorithm. I might have to agree with your original assessment to use the empty sets like the builtin does.
A sequence of length
n
includes a contiguous subsequence of lengthm
occursn - m + 1
times, why should 0 be a exception?Maybe
3:3
isn't the best notation for this, but there's an empty subsequence after the last item. It can be3:
,4:4
or whatever, but it's there. A built-in for example:If zero sums would still be valid, the it's an artificial special case, which isn't good.
But it's artificial too, so some solutions that naturally count all empty subsequences would have to handle this case separately, which isn't good.
There's an option of removing s = 0 from the input domain.
I would argue that logically, we should count at most one way to make an empty set.
For example, sum(xs[3:3]) doens't make sense for an array of length 3. By this logic, all of these return 0:
so there would be an infinite number of ways to sum to 0.
Would you consider this issue better resolved by stating in the problem that the length of the sub-array must be > 0 or by specifying that using an empty set counts as only 1 solution, even if it can be derived multiple ways?
I think it should be the latter because it makes sense that
should equal 1, not 0.
It's not specified that the subsequences must be non-empty, so there are 4 ways for
xs = [1, 2, 3]
:sum(xs[0:0])
,sum(xs[1:1])
,sum(xs[2:2])
,sum(xs[3:3])
.Added 10 smaller random tests
It seems like rolling_sum([1,2,3],0) should return 0 since there are no ways to make a sum of 0 with the integers given. You feel like that is not the proper solution?
The reference solutions fails at s = 0:
test.assert_equals(rolling_sum([1,2,3],0),4)
->0 should equal 4
Missing edge case tests with s = 0.
Loading more items...