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.
Yes - recursions are fascinating, however, be careful with them. Recursions could be double-edged swords...
Consider that each recursion level costs in memory on the stack. So if you have too many levels (self invocation) you would end up with a crash on lack of memory (or slowing down your whole computer as your code exhausts whole of the available memory).
In this specific case it is probably fine - we assume a number with a reasonable number of digits.
WoW
Oh neat!
We learned new stuff.
First and foremost "return n if n < 10" is the base case.
The map function applies a given function (in this case "int") to every item of something that is iterable. -> new for me!
Using the string function on the input n, you turn n into a string which is iterable. Therefore the map functiion can now apply a given function to each character of a string. -> the clever part!
Once the map function is done applying int to every digit, it is then all summed together.
WHAT
This comment is hidden because it contains spoiler information about the solution
I mainly meant efficient in the code golf sense of not requiring many characters. :) Yes, the floor division method is more performant.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Efficient way to get the digits. I'll have to remember that one.
Oh that's clever though! You figured out a way to get it done!
This comment is hidden because it contains spoiler information about the solution
yep)
But that's being super-pedantic since you're returning a list and not an array. It's a shared description. Imo returning a tuple in this context makes more sense for Python.
Even though they say return array not tuple test cases are passed.
Here you return tuple instead of array
Loading more items...