6 kyu

Squared Spiral #1

83 of 105lfhohmann
Description
Loading description...
Geometry
Performance
Algorithms
  • Please sign in or sign up to leave a comment.
  • jpdiogoNOVA Avatar

    This comment has been hidden.

    • lfhohmann Avatar

      I understand your point, but this Kata is looking for the fastest possible solution, all other solutions are meant to Time Out.

  • Kacarott Avatar

    Approved.

  • Blind4Basics Avatar

    reopening: if you checked that the O(log n) verison cannot pass the current version, you can close this one. but considering this solution is passing, I'm tempted to say that the perf tests aren't hard enough

    • lfhohmann Avatar

      I believe I finally managed to fix it. Tested your provided solution and it no longer passes.

      • Tuned tests so O(log n) solutions don't pass.
      Issue marked resolved by lfhohmann 4 years ago
  • Blind4Basics Avatar

    Reduced the amount of assertions to 1000

    very bad idea: doing so you're changing drastically the perf requirements. The idea was to silence the tests, and do more of them (because without all the assertions to print to the console, the code will execute faster).

    You're supposed to use something like this:

        for _ in range(numberOfTests):
            data = randomValue()
            expected = ref_sol(data)
            actual = user_solution(data)
            if actual!=expected:
                test.assert_equals(actual,expected)
                break
        else:
            test.pass_()
    

    the last line is about your last question. If you silence the tests that way and all results are correct, you need it so that at least one (succesful) assertion is done in the test.it block.

    Note: if you're not sure about what you're doing, don't resolve the issue and wait for feedback. That avoids the need for raising another one.

    edit: btw, you should have in your test suite a version in O(log n) of the solution, so that it's possible test it quickly, to tune the number of tests and the input range, making sure it cannot pass the tests. Maybe you already have that, I don't know: I cannot see the test suite, for now.

    • lfhohmann Avatar

      Ok, I see what you mean now, I'm gonna change the random tests suite to match your code.

      very bad idea: doing so you're changing drastically the perf requirements. What do you think, the random tests parameters should be? Keep it at 10,000 now that thes tests were silenced or change it to another value?

      As you can see, I'm no expert programmer, but I believe the current test suite solution is already O(1).

    • Blind4Basics Avatar

      yes it is O(1). To correctly setup the performances tests, you should use a O(log n) implementation, to make sure it doesn't pass the required number of tests (then you switch back to the O(1) one to update the kata)

    • lfhohmann Avatar

      I'm believe I'm missing the point, shouldn't the fastest implementation be prefered for the test suite, aren't we trying to measure the users code performance? And what is the advantage of going O(log n)?

      Issue marked resolved by lfhohmann 4 years ago
    • Kacarott Avatar

      The point is not to switch to O(log n), but to use a O(log n) solution to fine-tune your tests, to make sure that the O(log n) solution always fails, while the O(1) always passes.

  • Blind4Basics Avatar

    the random tests must be silenced if succesful: 10000 assertions are just killing the browser (note: don't forget to add one passing assertion at the end of the loop^, when all answers are good, and break the loop at first wrong answer). Once done, the perf requirements must be verified again, because the amount of data to currently transfer (assertions) is very time consumming, so maybe the setup won't be appropriate anymore

    and fixed tests with small values should be present too in the full test suite

    • lfhohmann Avatar
      • Reduced the amount of assertions to 1000
      • Changed random tests loop to break on first wrong answer
      • Added and separated fixed tests into small and large numbers tests

      And what do you mean exactly by "add one passing assertion at the end of the loop^, when all answers are good"?

      Thanks for the input

      Issue marked resolved by lfhohmann 4 years ago
  • Rud1 Avatar

    Great fun Kata !
    Wrong function name in Solution Setup : square_spiral shoud be squared_spiral.

  • mauro-1 Avatar

    Reference solution should use an O(1) algorithm.

    • Kacarott Avatar

      I was wondering if the range of tests should be raised to enforce a O(1) solution?

    • lfhohmann Avatar

      My idea was to create 2 different katas, this one for begginers and this other one, which enforces speed and performance

      Suggestion marked resolved by lfhohmann 4 years ago
    • Kacarott Avatar

      The problem is that finding a O(1) algorithm for this one is only slightly harder (if at all) than anything slower. I don't think there is enough of a difficulty gap to make the O(1) version worth a seperate kata.

    • lfhohmann Avatar

      I'll unpublish the other one and keep only this one, I'll also enforce the performance and speed through more tests and larger numbers.

  • mauro-1 Avatar
    • No fixed tests in main ("attempt") test suite
    • Tests should use nested describe/it blocks

    https://docs.codewars.com/authoring/guidelines/submission-tests/
    https://docs.codewars.com/languages/python/codewars-test

    • lfhohmann Avatar
      • Added fixed test cases to the "attempt" test suite
      • Tests were nested in describe/it blocks

      I believe everything should be right now. Thanks for the input.

      Issue marked resolved by lfhohmann 4 years ago