-1

So my problem is that in this lottery, you must select 6 numbers from the numbers 1 through 49. I have to do this with recursion and without itertools. I am really stuck as how else to continue to write my code.

Example input: 1 2 3 4 5 6 7

Output:

1 2 3 4 5 6

1 2 3 4 5 7

1 2 3 4 6 7

1 2 3 5 6 7

1 2 4 5 6 7

1 3 4 5 6 7

2 3 4 5 6 7

So I have my base case and everything else except the else part:

def lottery( number ):
    if len(  number ) == 6:
        return number
    else:

I have tried this but it does not work:

    else:
        output = list()
        for i in range( len( numbers ) ):
            rem = lotto(     numbers[i+1:] )
            output.append(   numbers[   :i] + rem )     

    return output
4
  • 1
    can you specify the task more clearly - do you want every possible combination of 6 numbers from the range 1-49? (there will be quite a few!) Commented Oct 31, 2014 at 8:59
  • 1
    possible duplicate stackoverflow.com/questions/13109274/… Commented Oct 31, 2014 at 9:09
  • Actually, I believe this duplicate question provides better answers to the question: stackoverflow.com/questions/104420/… Commented Oct 31, 2014 at 9:13
  • No I only want those out put, it is different from others since 123456 will be the same as 123465. Sorry my English is not that good. Commented Oct 31, 2014 at 16:42

1 Answer 1

1

I think you have some issues with your variable names. Try:

def lottery(numbers):
    if len(numbers) == 6:
        return numbers

     output = list()
     for i in range(len(numbers)):
         rem = numbers[i+1:]
         output.append(numbers[:i]+rem)
    return output
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.