Ad
  • Custom User Avatar
  • Custom User Avatar

    My recusion was not so good, but i did it

  • Custom User Avatar
  • Custom User Avatar

    See my fork for a simple, clear, non-recursive solution to this, using a bit of abuse of default input to shorten the solution. I prefer that a lot over putting if/else statements on a single line though.

  • Default User Avatar

    I'm curious about whether setting a default parameter is wise here - what if somebody using this particular implementation decided to override the default with an argument? The code would fail to return the correct answer, as outlined in the specification. What are others' thoughts on this as a general practice?

  • Custom User Avatar

    You can always just turn recursion limits off too (which also works here on codewars!)

  • Default User Avatar

    Yeah I agree if it were to be used in the real world it would probably be better and safer to do it iteratively and do some checks so it doesn't run forever. For these small kata I find it more fun to solve them in short and interesting ways though :)

  • Custom User Avatar

    I think recursion may be a little risky here, as the max recusion depth may be reached for strange values of n.

  • Default User Avatar

    In the example tests, "current list is %r"%r doesn't work. I honestly haven't used that syntax for string formatting in ages, I find that using the .format() string function a lot clearer as in: "current list is {0}".format(a)

  • Default User Avatar

    This would actually be a really good problem to help people get comfortable with recursion. Recursion was the first way I thought of solving this, I didn't realize until after submitting and seeing the other solutions that there was a constant depth to the nesting.

  • Default User Avatar

    I didn't realize that test cases can't be edited after publishing, which is unfortunate because it actually is well defined.

    dim(a + b) = max(dim(a), dim(b))

    This is because the vector space R^m is a subspace of R^n for all m <= n. For example, (1, 2) + (3, 4, 7) = (4, 6, 7) because (1, 2) = (1, 2, 0).

  • Custom User Avatar

    It's not well defined by default. What's the dimension of the result? How do you produce this result? Do you restrict the longer one, or do you interpolate the shorter one? All of that needs to go into the description and test cases, and AFAIK test cases cannot get changed after the kata has been published.

    If you would like to solve a kata where different vector sizes are permitted, it's probably up to you to write one yourself.

  • Default User Avatar

    I don't think there should be a restriction on adding and subtracting vectors of different dimension, addition of vectors of diffent dimension is valid mathematically so why not here?