Ad
  • Default User 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.

  • Custom User 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 ?

  • Default User Avatar

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

  • Custom User 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>

  • Default User Avatar

    The idea is that we calc each next number manually; we know that next number is one of 3 possible routes: to increase 1st expo, 2nd or 3rd by 1. So we calc all 3 numbers (what they will become with increased expo and pick minimal), we increase expos of taken step, save number and repeat all again.

  • Default User 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.

  • Default User Avatar
  • Custom User Avatar

    How would you prove that it always generates a cycle?

    Note that there are interesting cycles, for instance from 4668999 we get:

          4668999,
        273477659,
       1696679985,
     189949768294,
    6563842477374,
    
  • Custom User 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)
    
  • Default User Avatar

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

  • Custom User Avatar
  • Default User Avatar

    I have added tests with small numbers to test cases, big numbers to sample tests, and am now using the test framework for python.

  • Default User Avatar

    side note: if the test cases get run alphabetically (by their description) it's best to assure those smaller tests are run before the biger ones

  • Custom User 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

  • Default User Avatar

    .

  • Loading more items...