[ create a new paste ] login | about

Link: http://codepad.org/9vcM5noi    [ raw code | output | fork ]

Python, pasted on May 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def print_array(arr):
    for elem in arr[:-1]:
        print elem,
    print arr[-1]

def print_repeated_permutations(elements, selected):
    if len(selected) == len(elements):
        print_array(selected)
        return

    for elem in elements:
        print_repeated_permutations(elements, selected + [elem])

#x = input("How many item do you want to row?: ")
x = 3
num=[]
for i in range (1,x+1):
    num.append(i)

print_repeated_permutations(num, [])


Output:
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3
2 2 1
2 2 2
2 2 3
2 3 1
2 3 2
2 3 3
3 1 1
3 1 2
3 1 3
3 2 1
3 2 2
3 2 3
3 3 1
3 3 2
3 3 3


Create a new paste based on this one


Comments: