7 kyu

Moving Average

Description
Loading description...
Algorithms
Logic
Mathematics
Lists
View
AllIssues6Questions2Suggestions2Show Resolved
  • Please sign in or sign up to leave a comment.
  • hobovsky Avatar

    This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/208.
    Please join the discussion to help us identify duplicate kata and retire them.

  • oded_Bartov Avatar

    i solved the kata and all the tests are ok. but when i click the 'attempt' button i get this error: Traceback (most recent call last): File "/runner/frameworks/python/cw-2.py", line 111, in wrapper func() File "main.py", line 30, in edge_case_tests assertFloatArrayEqual(moving_average([50,51,52,53,54],5), [52.0]) File "main.py", line 12, in assertFloatArrayEqual raise e File "main.py", line 5, in assertFloatArrayEqual final = [abs(x[0]- x[1]) < epsilon for x in zip(actual,expected)]

  • soggybiscuit Avatar

    Why am I getting dinged for not having enouch decimal places and rounding in my answer?

    [212.0, 226.33333333333331, 240.99999999999997, 236.33333333333334, 173.66666666666666] should equal [212.0, 226.33333333333334, 241.0, 236.33333333333334, 173.66666666666666]

  • user9644768 Avatar

    Updated the description to make it more readable, and approved as 7 kyu despite of average rank of 6 kyu.

    7 kyu kata represent a beginner programming level. At this level the kata will generally challenge 
    users on their core language and API reference knowledge. Tasks such as:
    
        Iterating arrays and returning a subset of values <---- which is exactly what one have to do here.
    
  • krishp Avatar

    I have a question about the test cases. I have solved all of the cases except one. The list of values is [35.57142857142857, 29.857142857142858, 25.571428571428573, 18.428571428571427, 11.857142857142858, 6.285714285714286, 0.0]. I was wondering why this list should return None. Could someone explain this to me?

  • john c Avatar

    Why doesn't the system let me see the solutions by other members? It does show my solution as valid in "My solutions". It's been about 18 hours now since I posted it.

  • FArekkusu Avatar

    This comment has been hidden.

  • Unnamed Avatar

    Returning [] passes the random tests because of zip. And given that everything is an integer, I'd just use assert_equals with lists.

  • Blind4Basics Avatar

    result format should be a list of floats rounded to the 2 decimal ex.

    No, no, three time no and even more of that. That's the worst thing to do with your kata. Just build a real assertion for arrays of floating point values, but DO NOT round here.

    the very least would be something like that:

    def assertFloatArrayEqual(actual, expected, epsilon=1e-9):
        try:
            test.assert_equals(len(actual), len(expected), "Expected and actual differ in length")
            test.expect(all(abs(a-b)<epsilon for a,b in zip(actual,expected)), f"{actual} should equal {expected} (margin={espilon})"
        expect Exception as e:
            test.fail("something went wrong")
            raise e
    
  • Blind4Basics Avatar

    your kata is lacking some edge cases:

    • n<1?
    • n>len(input_list)?

    if you don't wanna test for them, that's ok, but you have to tell it in the description, then.

  • Unnamed Avatar

    iterable is always a list. If it's called iterable, then other iterables (including iterable once and without known length) should be tested.

  • john c Avatar

    I completed the kata and sent the solution out but the system still says: "Since you have not yet solved this kata we have hidden the solutions from you..."

  • Voile Avatar

    You need to account for possible floating point errors in the tests.