Ad
  • Custom User Avatar

    @fibritco: you're supposed to apply a reduction of all the elements in the range, using that operator.

  • Custom User Avatar

    a+b+c is unambiguous as a result of the associative property of addition.

  • Custom User Avatar

    I didn't intend for the performance aspect of this kata to be concealed. In trying to be brief, all I said in the description was "Some tests will include very large numbers."

    While the algorithmic runtime is important here, a scheme can be devised that is more of a function of the number of digits in the input. Maybe it would be less of a surprise if the input were a string rather than an integer -- but I imagine I'd still have folks converting that to an integer type and doing math with it.

    Regardless, a major hint is to think about the challenges with finding the next smaller number of a relatively small input by hand. I don't know your implementation, but consider an input of: 21000. Would a person solving this really need to test whether 11999, 11998, 11997, and so on -- contain the same digits? If you can think of strategies for rearranging the digits you'll be in a better position, but naively considering permutations of all digits in order to find the next smaller is likely to time out (as the count of permutations involves factorials that can also grow quite large -- the 5 digit number would have 5! or 120 different permutations most of which will be identical with the repeated digits.) Thinking about the conditions where there are no solutions can help too. If you can intuit that the next smaller number of 21000 is 20100 -- how can you knwo that is the right answer?

    Hoping that this kata is fun and that folks learn something in their attempts. Cheers!

  • Custom User Avatar

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

  • Custom User Avatar

    Generally, your solution is expected to be blazing fast. it should run more or less the same for n=543210 and n=9876543210. Expected complexity is O(log n) (approximately), while yours is probably O(n).