Struggling with recursive function, what am I doing wrong
Question: I'm fairly new to python and understand that recursion is an important concept
to grasp. I've been dabbling with various scripts to exercise my knowledge and
have come up with the following script to simulate a lottery draw, where you
simply draw six from 49 numbers and compare them with another six to see if
you've won. I'm struggling though with the recursive function taking the value
of another function.

I'm sure it's going to be straightforwardish, but cannot fathom it myself.

Here's my code so far:

    
    
    from random import randint
    
    def drawSix():
        six = []
        while len(six) < 6:
            a = randint(1,49)   
            if a not in six:
                six.append(a)
        return sorted(six)
    
    def lottery(draw,ticket):
        if draw == ticket:
            return 'win'
        return lottery(drawSix(),drawSix())
    

I call the function with lottery(drawSix(),drawSix())

and get the following recursively.

    
    
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        lottery(drawSix(),drawSix())
      File "/Users/johnhopkins/Desktop/lottery.py", line 14, in lottery
        return lottery(drawSix(),drawSix())
    


Answer: 
    def lottery(draw,ticket):
        if draw == ticket:
            return 'win'
        return lottery(drawSix(),drawSix())
    

The odds of you actually generating two identical tickets are quite large,
well over 1000 which is the maximum stack size of Python.

You need to either do this iteratively to avoid blowing your stack.

    
    
    def lottery(draw,ticket):
        while draw != ticket:
            draw, ticket = drawSix(), drawSix()
        return "win"
    

Note this has a very ugly `O(n)` of `O(inf)` you could end up running this
forever if you were unlucky and still not finding a winning pair

