Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
cool recursion
My recusion was not so good, but i did it
Beautiful recursion!
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.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?
You can always just turn recursion limits off too (which also works here on codewars!)
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 :)
I think recursion may be a little risky here, as the max recusion depth may be reached for strange values of n.
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)
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.
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).
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.
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?