6 kyu

Midpoint Sum

771 of 1,307AlejandorLazaro
Description
Loading description...
Lists
Fundamentals
  • Please sign in or sign up to leave a comment.
  • FArekkusu Avatar

    Test.assert_equals should be used instead.

  • FArekkusu Avatar

    No random tests.

  • esko1779 Avatar

    You need to clarify the answer in cases like [1, 0, 0, 0, 1]. Should it be first index or any or what? What is the right answer for this test? Also can't see any random tests for Python (I used version 3.4.3).

  • paragonHex Avatar

    I wonder if there is a better solution for this than a greedy one. Mapping and summing n seems like big time over"clever"ing (and iterating).

  • nickie Avatar

    I wonder how people consider as "best practice" and "clever", for this exercise, a bunch of solutions that sum the list of numbers again and again...

  • novak22 Avatar

    This comment has been hidden.

  • fuzzy_by_nature Avatar

    In the final test I am getting 1 as the midpoint sum and I dont really understand how that isn't the correct answer. [1, (1), 1, ...] 1 == 1 when comparing from the index (1) within the parenthesis.

  • Vranos Avatar

    def midpoint_sum(ints): if len(ints) <= 2:
    return None for i in range(len(ints)): left = sum(range(ints[i-1])) right = sum(range(ints[i+1,len(ints)])) if sum(left)==sum(right): return i return None

    Hey peeps. I am getting an error because it is encountering tuples, any clue why?

  • jammblues Avatar

    You have a small mistake in the test cases: Test.expect(midpointSum([-10,3,7,8,-6,-13,21]) == 4, "[8,-6,-13,21] should equal 4")

    should be Test.expect(midpointSum([-10,3,7,8,-6,-13,21]) == 4, "[-10,3,7,8,-6,-13,21] should equal 4")

  • wthit56 Avatar

    I think you should specify (and perhaps provide an example) that the integers may be negative, as this will drastically change what kind of implementation is possible. Also, the zeros are a bit confusing as it is. Instead of Don't treat the list as if it had floating zeros before/after the first/last elements, you could simply say the first or last index cannot be considered the "midpoint". This would cover what you explained, but much clearer, and easier to slot into the current understanding of the problem. Along the same lines, the "Ending in non-zero" is just super-confusing, so should be changed.

    Still, I had a lot of fun figuring this out, so good job on coming up with it in the first place!

  • GiacomoSorbi Avatar

    I am not 100% ok with edge cases: you either state in the description that the first and last item can't be the solution or you let them pass, as they could properly be the required midpoints.

    Other than than, simple and interesting kata :)