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.
I would say yes that pattern recognition is a skill, as well as understanding the problem. Much of the complexity of this problem is in understanding it.
@sweetmercury true, i wished i actually written the resulting output rather than the triangle.
Lol
Great!! Thank you for Kata! I enjoyed it!!!
I'm sure you've solved this by now, but just in case...
You know that there can't be more WUBs than the length of the given title / 3 (because WUB takes up three characters). Can you replace the groups of WUBs with a single space if you know how many there are?
This comment is hidden because it contains spoiler information about the solution
Please, mark your post as having spoiler content next time, you're disclosing the solution. About your question, yes, that solution is faster and speed is one of the parameters you can measure a solution with.
This comment is hidden because it contains spoiler information about the solution
Much appreciated.
Read this specially the memory stack part. If you don't return the call, it'll run your code n times, the result will be lost when returning from the stack and the default return value of Python is
None
. Use Pythontutor to see the difference.Oooooh, my original code was actually returning None (I ran it in another editor so I could see specifically what it WAS returning). That's even more curious. Why would it return None if it knows what the counter is? (Don't get me wrong, I know now to make sure I'm returning along the way, but that's still super confusing)
Ahhh, ok. I thought I was changing my return line, not the earlier line calling persistence. That definitely fixed it. Thank you. (and this is now a point I'm not likely to forget anytime soon)
I'm not 100% clear why that's needed though, because how is the program itself able to know what the counter is if I print out that variable, but it goes all wonky when I try to return it if I wasn't recursively returning it along the way? Real Python has a whole page on recursion, but they aren't really explaining the why there either, so my curiousity still abounds.
It's not the last line you have to change, only change the line I wrote first there (the line 8 in your posted code), with the other one, do you get why you should do that? Try reading a little more about how recursion works if not. Recursion is not that easy to understand if you're only starting to code, you could have used an iterative solution instead. This will be helpful to you too.
When I change the last line to return persistence(first_number, counter), I get an infinite loop
Read my answer again, I told you exactly what was wrong. I wasn't impolite at all.
I hope this is clear enough.
Loading more items...