Ad
  • Custom User Avatar

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

  • Custom User Avatar

    Writting down the detailed steps on a paper helped me to clarify the algo ;)

  • Default User Avatar

    Somethings wonky with negative test outputs.

    I have derived the negative extension myself, as well as checked it against Wikipedia's...and yet it still gives errors on random negative numbers

  • Custom User Avatar

    Cheers! It looks like you solved the kata.

    I suppose you've figured out that source.Count() enumerates the source and which is why it fails the tests. Using Count as an existence test is bad because the enumerable could be very large and costly to determine when all that is desired to know is whether there is at least one. The LINQ operator for existence tests is Any which does such a test -- but even calling Any would fail the test since it enumerates the first element of the enumerable.

    Imagine the following enumerable for a test case in CodeWars:

    private IEnumerable<int> TimeOutEnumerable()
    {
        Thread.Sleep(TimeSpan.FromDays(1));
        yield return 1;
    }
    

    Implementations with early-out checks for source.Count() or source.Any() will encounter the CodeWars timeout and have their executions stopped.
    Thanks for your questions and for doing the kata.

  • Custom User Avatar

    No, it should not be negative. Yes, you are missing the "Hint I" from the description.

  • Custom User Avatar

    Hello,

    How fast was your solution?
    Mine passes n = 10e7 in 1.394 seconds but it still times out during the random test.

    [edit] for anyone wondering the threshold is to be able to return n=10e7 in approximately less than 1 second.