0

Possible Duplicate:
How to generate all permutations of a list in Python

I want to get all possible combination having values range from 0-7.

For eg

arr[0]= 0,1,2,3,4,5,6,7
arr[1]=1,2,3,4,5,6,7,0
arr[2]=2,3,4,5,6,7,1,0

arr[3]= 0,1,2,3,4,5,6,7
arr[4]=1,2,3,4,5,6,7,0
arr[5]=2,3,4,5,6,7,1,0

arr[6]= 0,1,2,3,4,5,6,7
arr[7]=1,2,3,4,5,6,7,0
arr[8]=2,3,4,5,6,7,1,0

arr[9]= 0,1,2,3,4,5,6,7.....

and so on.

I want to get all possible combination with no repeating digits from a given set of value i.e 0-7.

Community
  • 1
  • 1
Ronak
  • 974
  • 6
  • 14
  • 1
    Why have you tagged the question with "probability"? – aioobe Jun 04 '12 at 11:54
  • 3
    Looks like you're on your way--keep chuggin'. Seriously--what language? What have you tried? There are examples of this all over the net--what didn't work about them? – Dave Newton Jun 04 '12 at 11:54
  • 3
    @aioobe Because the probability of anyone helping with the question as-is is low. – Dave Newton Jun 04 '12 at 11:55
  • @Dave Can you provide me solution i have tried all over net i didnt find it. I think you are great researcher and you can provide me the url where it has been posted.. – Ronak Jun 04 '12 at 12:11
  • @Ronak Search for "combination permutation" plus whatever language you're trying to do this with. Please show some effort--this is a 100%-solved problem, some languages even have a function call that does it *for* you. – Dave Newton Jun 04 '12 at 12:16
  • ruby has a method [permutation](http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-permutation): `(0..7).to_a.permutation.to_a` – Stefan Jun 04 '12 at 12:20

1 Answers1

0

indeed this will all depend on the language... Here is a short try in python:

>>> from itertools import permutations
>>> l = [0,1,2,3,4,5,6,7]
>>> for p in permutations(l):
    print p


(0, 1, 2, 3, 4, 5, 6, 7)
(0, 1, 2, 3, 4, 5, 7, 6)
(0, 1, 2, 3, 4, 6, 5, 7)
(0, 1, 2, 3, 4, 6, 7, 5)
(0, 1, 2, 3, 4, 7, 5, 6)
(0, 1, 2, 3, 4, 7, 6, 5)
...
Emmanuel
  • 13,935
  • 12
  • 50
  • 72