Ad
  • Default User Avatar
  • Custom User Avatar

    This would be a different kata, it's hard do it well, and probably nearly impossible to do in several languages. This is an old kata that has been solved about 100k times, it is not going to be changed now.

    Edit (I realize I misread you)

    Suggestions of challenges that are not enforced don't make much sense; several have been removed in some old katas, with reason, IMO. So, no. If someone wants to challenge himself, he's still free to do it.

  • Custom User Avatar

    @hobovsky

    to be completely frank, i see @akar-0's point as irrelevant to my suggestion.

    plenty of katas specify a max value for an input. that is the suggestion i'm making - not to explain an implementation or arbitrary list of possible solutions. like you said, "stating limits of problems is always [a] good thing."

    additionally, it's difficult to pin point advantages and disadvantages without knowing the constraints of a problem, regardless of skill level. i'd even make the argument that beginners especially are given constraints to guide them in the right direction, and that a beginner submitting a recursive solution would have trouble debugging their work given the current state of the kata.

  • Custom User Avatar

    The point is, that description will never be able to cover all possibilities solvers could ever come up with. There has to be some point after which solutions will be considered so bad they are not worth explaining. For example, one day a user comes and complains "I added thread.sleep(100) into my solution to make debugging easier, and it works on my machine and times out on Codewars. You need to tell what n can be so I know how long my threads can sleep."

    Now the question would be: is a recursive solution bad enough to make it fail without any explanation? I would say: I am not sure, but I think it's not. Some would say that if you are going to use recursion, you should be able to know its advantages and disadvantages and know when (and how) it can fail. On the other hand, this kata is supposed to be 8 kyu, aimed at total beginners, who may not understand many things. Additionally, stating limits of problems is always good thing. I think that waay too many kata do not provide this information, while they really should.

  • Custom User Avatar

    @akar-0

    what exactly is your point?

    as i just stated, mainly for context at that, in my case, i had an issue with my original implementation when n > 8059. i'm aware a recursive approach is inefficient for some values of n.

    i was suggesting that the description be amended to hint that a recursive implementation will timeout because it is not clear how large n can be.

  • Custom User Avatar

    8000 is not a large number (the largest value tested in JS is 10000). The recursive approach is very inefficient in such a case, a function requiring thousands of recursions must be expected to crash due to stack overflow.

  • Custom User Avatar

    for the js/ts version of this kata (and wherever else this may apply):

    a note should be added to the description that the function is expected to handle large values of n. additionally, at least one test case should be added reflecting this caveat.

    i originally went for a recursive solution, and based on the test cases, i was surprised to find that my original implementation timed out (when n > 8059 in my case).

  • Default User Avatar

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

  • Custom User Avatar

    @Rlaur2 how so? it would be great if you could explain your thinking instead of providing a baseless response. furthermore, simply adding "challenge: complete this kata without converting value to a string" to the end of the description would do the trick. anybody who wants to can, and those who don't can just ignore it.

    i also took a peek at your solution and as i suspected, you solved this kata by converting value to a string. i originally completed this kata in typescript, but i completed it in javascript just to show you how it can be done. feel free to take a look if you aren't already familiar with the implementation.

  • Custom User Avatar

    That's essentially a whole different question at that point.

  • Custom User Avatar

    awesome kata!

    in the spirit of diversifying solutions, a nice amendment to the description would be challenging folks to implement the function without converting value to a string 😁