Ad
  • Custom User Avatar
  • Custom User Avatar

    No, it is that the reference solution is consistently wrong when s == l[0] and len(l) > 1. For example:

    l = [1, 2], s = 1
    
    1 should equal 0
    
  • Custom User Avatar

    The kata has performance requirements, so it should specify input range.

  • Custom User Avatar

    Good question. I'll look into it.

  • Custom User Avatar

    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], and s = 3.

    I find these four solutions all summing to 3:

    1. sum(l[0:1]) => sum([3]) => 3
    2. sum(l[0:3]) => sum([3, -1, 1]) => 3
    3. sum(l[6:7]) => sum([3]) => 3
    4. 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?

  • Custom User Avatar

    updated as above.

  • Custom User Avatar

    I went with your original premise and updated the description with a hint: somestring.count('')

    So in the test cases, there is now:

    test.assert_equals(rolling_sum([1,2,3],0),4)
    
  • Custom User Avatar

    I think I see what you are saying. If we say that sub-arrays must have length > 0 then

    rs([],0)
    

    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.

  • Default User Avatar

    I would argue that logically, we should count at most one way to make an empty set.

    A sequence of length n includes a contiguous subsequence of length m occurs n - m + 1 times, why should 0 be a exception?

    For example, sum(xs[3:3]) doens't make sense for an array of length 3. By this logic, all of these return 0:

    Maybe 3:3 isn't the best notation for this, but there's an empty subsequence after the last item. It can be 3:, 4:4 or whatever, but it's there. A built-in for example:

    >>> 'aaa'.count('')
    4
    

    the length of the sub-array must be > 0

    If zero sums would still be valid, the it's an artificial special case, which isn't good.

    specifying that using an empty set counts as only 1 solution, even if it can be derived multiple ways

    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.

  • Custom User Avatar

    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:

    sum(xs[4:4])
    sum(xs[4:9999999])
    sum(xs[-1:-1])
    

    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

    rolling_sum([],0)
    

    should equal 1, not 0.

  • Default User Avatar

    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]).

  • Custom User Avatar

    Added 10 smaller random tests

  • Custom User Avatar

    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?

  • Default User Avatar

    The reference solutions fails at s = 0:
    test.assert_equals(rolling_sum([1,2,3],0),4) -> 0 should equal 4

  • Default User Avatar

    Missing edge case tests with s = 0.

  • Loading more items...