Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    @sweetmercury true, i wished i actually written the resulting output rather than the triangle.

  • Custom User Avatar
  • Default User Avatar

    Great!! Thank you for Kata! I enjoyed it!!!

  • Custom User Avatar

    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?

  • Custom User Avatar

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

  • Custom User Avatar

    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.

  • Custom User Avatar

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

  • Custom User Avatar

    Much appreciated.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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)

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    When I change the last line to return persistence(first_number, counter), I get an infinite loop

  • Custom User Avatar

    Read my answer again, I told you exactly what was wrong. I wasn't impolite at all.

    persistence(first_number, counter) # call to the function
    return persistence(first_number, counter) # returning the call to the function
    

    I hope this is clear enough.

  • Loading more items...