-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
Community
  • 1
  • 1
Sone Nine
  • 115
  • 1
  • 9
  • 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!) – codebox Oct 31 '14 at 08:59
  • 1
    possible duplicate http://stackoverflow.com/questions/13109274/python-recursion-permutations – Mazdak Oct 31 '14 at 09:09
  • Actually, I believe this duplicate question provides better answers to the question: http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python – go2 Oct 31 '14 at 09: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. – Sone Nine Oct 31 '14 at 16:42

1 Answers1

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
wallyk
  • 56,922
  • 16
  • 83
  • 148
K Mo
  • 2,125
  • 8
  • 16