Ad
  • Custom User Avatar

    It's not a bug, it just performance test...
    You went over primitive range.

  • Custom User Avatar

    Sorry but your string doesn't throw any exception. I got 38892296835628857864 if you want to create a simple test case. Good luck

  • Custom User Avatar

    @zollipaul159 .. Well ..

    • mmmm I bet you've attempt solving the kata in Java , haven't you ?? :wink: :wink:
    • Okay , revise the Notes Section in the Description , and you'll figure out Why :wink: :wink: ..
    • Happy to the first to follow you Bro .. hope you the best .. regards .. Zizou :blush: :blush:
  • Custom User Avatar

    You don't technically need any of those things, but the first thing you asked about is useful.

  • Custom User Avatar

    I don't think you're ready for Code Golfing if you're asking such questions ;)

  • Custom User Avatar

    You have to count the number of ways you can take n-1 elements out of n which sum to a given number.

    So you iterate over the array and for every element, compare the sum of all the other elements with the given number.

    Now precompute the sum of all elements and subtract that from both sides of that comparison. And add the given number to both sides. What you're left with is comparing -element to -sum+given. Negate both sides. ( Both sum and -given are inside the reduce, but you get that part. )

    How did I do it? Small steps, and some sleeps between them. Inspiration comes slowly to me. :P I iterate on solutions a lot. Over time, you see patterns. There is no substitute for spending the time.

    Answer your question?

  • Custom User Avatar

    Inside the function, like this:

    func persistence(for num: Int) -> Int {
       print(num)
       return 0 
    }
    
  • Custom User Avatar

    Are you sure the argument is 1? Use print(num) to see what it is. The error is saying your function returns 1 instead of 2.