Ad
  • Custom User Avatar

    System.out.println should work in java tests, and, as a matter of fact, it worked when I tried it. Are you sure you get nothing printed? Are you sure you are not trying to print an empty string or something like that?

  • Custom User Avatar

    I'm trying to practice Java at the moment and am a native python user. I was wondering what's the reason why you can't simply type System.out.println() to debug a problem? Whenever I use System.out.println(x), it amounts to nothing on the console.

  • Custom User Avatar

    Test.assert_equals takes two arguments: the value your function returns and the expected value, your function only takes a single argument, see the function definition.

    def find_missing_number(number):
    

    From the kata description:

    Write a function that takes a shuffled list of unique numbers from 1 to n with one element missing (which can be any number including n). Return this missing number.

    In [2, 3, 4] the missing number is 1 and your code doesn't work for that.

    BTW, when you make a single line code block, there is no need for the python label, use it only when doing a multiline one (single backtick vs triple backticks)

  • Custom User Avatar

    @Chrono79 Understood. Sorry about that. I believe I am confused about the code written in sample test. It says python Test.assert_equals(find_missing_number([2, 3, 4]), 1).
    Does this mean that the function should have two parameters? first for the actual list and the second for that missing number? Or am I overthinking?

  • Custom User Avatar

    Try keeping the same problem in the same thread, opening more than one is a little messy. Apart of timing out, your code is failing two sample tests, so, first I would try making my code pass the sample test and then I'll try making it faster, because the final tests are really long, note there is a PERFORMANCE tag in this kata. Try using some math.

  • Custom User Avatar

    Repost
    Here is the updated code. But it gives the timeout error when i try to attempt the kata.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Sorry about this. I didnt realize that it was showing an error. I shall repost with the updated code.

  • Custom User Avatar

    I typed python *mycode* in the previous comment. Which is exactly earlier. Please let me know if the problem still persists.

  • Custom User Avatar

    C Translation is ready (author is inactive).

    Also, the random tests in C# seem really bizzarre, and I don't think they're doing what the author intends. They appear to be running 7000 tests over the same set of 2000 arrays, and none of the test sizes come close to the JavaScript performance tests. I'm hesitant to change them, though, as many existing solutions could start failing due to signed integer overflow.

  • Custom User Avatar

    ah yes, my mistake. the OP had a previous post where the code would sometimes pass. then that code was edited several times, so I've lost track

  • Custom User Avatar

    It's not the indentation, it's the lack of initialization.

  • Custom User Avatar

    Hi @opeth22, your code indentation causes this: UnboundLocalError: local variable 'answer' referenced before assignment, so repost your code with the correct indentation

  • Custom User Avatar

    This code gives the answer of the missing number but also gives the timeout error. Need help!

  • Custom User Avatar

    I did it with callback function but it solution had problem with memory. I broke my mind. I have red a tip that I have to think about math solutions. Done.

  • Loading more items...