6 kyu

Prime Cycles

174 of 201neuralStep
Description
Loading description...
Puzzles
  • Please sign in or sign up to leave a comment.
  • Alexenon Avatar

    When does a sequence ends ? My algorithm finds max until same number is generated second time. I pass 20 tests and then fails due my maximum is smaller than expected. Could someone please explain me when method should return maximum value :)

    expected:<615043> but was:<1230086>

    • jrico Avatar

      Most likely, you are not including the initial n value. It also happened to me :)

    • Alexenon Avatar

      @jrico, i changed from return max to return Long.max(n, max) and still my algorithm can't find the maximum value in a sequence for numbers bigger than 1_000_000

      I am returning maximum value when same number occurences second time in the sequence. You did the same ?

    • jrico Avatar

      @Alexenon Yes I did. The sequence starts at n and you genenerate new values until a value is already seen in the sequence. Pick the maximum of them. This should work even for big (long) numbers.

  • akar-0 Avatar

    Test cases in Python would be better if they were factorized to avoid repetitions. It's easy to create a generic function dotest that does the job for all tests, fixed and random. That would lighten the tests page and would be much more readable. Something like:

    def dotest(n, expected):
      actual = user_function(inputs)
      test.assert_equals(actual, expected, f"Test failed with n = {n}")
      
      # then just do in the tests:
      dotest(n, expected)
    
    • lechevalier Avatar

      Not that interesting to create a function just to encapsulate a call to another method although I agree on the fact that test cases in example can be inserted in a list with an explicit error message.

  • lechevalier Avatar

    You should add in description that this procedure always generates a cycle.

  • Blind4Basics Avatar

    1/ you didn't add the tests with small numbers to the test cases part 2/ you didn't add 1 or 2 tests with big number to the sample tests part 3/ I didn't notice before, but you have to use the new test framework, for python

  • rowcased Avatar

    No random tests

    • neuralStep Avatar

      Why are random tests needed? And how would you even evaulate the correct answer for a random input?

    • Blind4Basics Avatar

      damn... I thought those were random tests... (see below). They are required because otherwise a user can cheat the kata very easily without actually solving the task.

      to see how to do them, look a the tests suites of katas (recent ones) you already solved.

    • neuralStep Avatar

      Random tests added for both Python and Java.

      Issue marked resolved by neuralStep 5 years ago
  • Blind4Basics Avatar

    Hi,

    • You need fixed tests too in the test cases part (you can use those of the sample tests)
    • and you should add one or 2 tests with big numbers in the fixed tests (both test cases and sample tests)
    • neuralStep Avatar

      I'm not sure at all what you mean in your first point. What fixed tests? What test cases?? All the tests in the test cases use big numbers.

    • Blind4Basics Avatar

      See above: I took the tests for random whil they are fixed ones... x/

      => you should add the sample tests with small inputs too in the "test cases" part ; you should add one or two tests with bid numebrs in the "sample tests" (might be named "example tests" in the edit panel) ; and add random tests, finally

    • neuralStep Avatar
      Issue marked resolved by neuralStep 5 years ago
  • FArekkusu Avatar

    The actual/expected values are flipped in Python.

  • RazNaot Avatar

    Not clear what happens with 13: 1st prime is 2, 3rd is 5, multiple is 10. Now what? what do we do with the zero?