Problem:

Permutation Enumeration

 

    For given an integer $n$, print all permutations of $\{1, 2, ..., n\}$ in lexicographic order.

Input

  An integer $n$ is given in a line.

Output

  Print each permutation in a line in order. Separate adjacency elements by a space character. 

Constraints

  
$1 \leq n \leq 9$

Sample Input 1

2

Sample Output 1

1 2
2 1

Sample Input 2

3

Sample Output 2

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1



Sample input:
2


Sample output:
1 2
2 1

Submission status: Accepted

Solution code:
import itertools

def print_elements(a):
    print(' '.join(list(map(str, a))))

n = int(input())
for per in list(itertools.permutations([i+1 for i in range(n)])):
    print_elements(per)

Submission status: Accepted

Solution code:

def permutations(n):
    """Yields all permutations of {1, 2, ... , n}

    >>> list(permutations(2))
    [[1, 2], [2, 1]]
    >>> list(permutations(3))
    [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
    """

    xs = list(range(1, n+1))
    yield xs[:]

    while True:
        i = n - 1
        while i > 0 and xs[i-1] > xs[i]:
            i -= 1
        if i > 0:
            i -= 1
            j = i + 1
            while j < len(xs) and xs[j] > xs[i]:
                j += 1
            xs[i], xs[j-1] = xs[j-1], xs[i]
            xs = xs[:i+1] + list(reversed(xs[i+1:]))
            yield xs[:]
        else:
            break


def run():
    n = int(input())

    for ps in permutations(n):
        print(" ".join([str(x) for x in ps]))


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
# AOJ ITP2_5_D: Permutation Enumeration
# Python3 2018.6.24 bal4u

def next_permutation(a):
    i = len(a)-2
    while i >= 0 and a[i] >= a[i+1]: i -= 1
    if i < 0: return False
    j = i + 1
    k = len(a) - 1
    while a[i] >= a[k]: k -= 1
    a[i], a[k] = a[k], a[i]
    a[j:] = a[:j-1:-1]
    return True

n = int(input())
if n == 1: print(1)
else:
	a = [i for i in range(1, n+1)]
	print(*a)
	while next_permutation(a): print(*a)

Submission status: Accepted

Solution code:
from itertools import permutations
import sys

write = sys.stdout.write
N = int(sys.stdin.readline())

for p in permutations(map(str, range(1, N + 1)), r = N):
    write(" ".join(p))
    write("\n")

Submission status: Accepted

Solution code:
def resolve():
    import itertools
    n = int(input())
    for a in itertools.permutations(list(range(1, n + 1))):
        print(*a)


resolve()

Submission status: Accepted

Solution code:

import itertools
import copy
n = int(input())
*a, = itertools.permutations(range(1,n+1),n)
for i in a:
    print(*i)

Submission status: Accepted

Solution code:
from itertools import permutations

a = [i+1 for i in range(int(input()))]

for i in permutations(a):
    print(*i)

Submission status: Accepted

Solution code:
from itertools import permutations
n = int(input())
a = [i + 1 for i in range(n)]
for p in permutations(a):
    print(*p)

Submission status: Accepted

Solution code:
from itertools import permutations

n = int(input())
nums = (str(i) for i in range(1,n+1))
ans = (' '.join(t) for t in permutations(nums))
print("\n".join(ans))

Submission status: Accepted

Solution code:
from itertools import permutations
n = int(input())
l = list(range(1, n+1))
for v in permutations(l):
    print(*v)

Submission status: Accepted

Solution code:
from itertools import permutations

def main():
    n = int(input())
    a = [i for i in range(1,n+1)]
    perm = list(permutations(sorted(a)))
    for per in perm:
        print (' '.join(map(str,per)))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

n = int(input())
L = [i for i in range(1, n + 1)]

p = itertools.permutations(L)
L2 = sorted(p)

[print(*L2[i]) for i in range(len(L2))]

Submission status: Accepted

Solution code:
import itertools
[print(" ".join(list(map(str, x)))) for x in itertools.permutations(range(1,int(input())+1))]

Submission status: Accepted

Solution code:
import itertools

n=int(input())
for i in itertools.permutations([i+1 for i in range(n)]):
    print(" ".join([str(j) for j in i]))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**8)

n = int(input())
a = [i for i in range(1, n+1)]

def permute(deep, ans):
    if deep == 0:
        print(ans.strip())
    else:
        for i in a:
            if str(i) not in ans:
                permute(deep-1, ans+' '+str(i))

permute(n, '')

Submission status: Accepted

Solution code:
n=int(input())

import itertools
p=list(itertools.permutations(range(1,n+1), n))
p=[print(*p[i]) for i in range(len(p))]

Submission status: Accepted

Solution code:
from itertools import permutations
n = int(input())
p = list(permutations((str(i) for i in range(1,n+1))))

# for i in p:
#     print(*i)
ans = (' '.join(t) for t in p)
print('\n'.join(ans))

Submission status: Accepted

Solution code:
def solve():
    from itertools import permutations
    n = int(input())
    nums = (str(i) for i in range(1, n + 1))
    ans = (' '.join(t) for t in permutations(nums))
    print('\n'.join(ans))

solve()

Submission status: Accepted

Solution code:
from itertools import *
n = int(input())

for i in permutations(range(1,n+1)):
    print(" ".join(map(str, i)))

Submission status: Accepted

Solution code:
import itertools


if __name__ == "__main__":
    n = int(input())
    nums = [num for num in range(1, n + 1)]
    nums_permutated = list(itertools.permutations(nums))

    for elem in nums_permutated:
        print(" ".join([str(num) for num in elem]))

Submission status: Accepted

Solution code:
#組み込み関数頼み
import itertools
n = int(input())
a = range(1, n+1)
lst = []
for _ in itertools.permutations(a, n):
    lst.append(_) 
lst.sort()
ln = len(lst)
for _ in range(ln):
    print(*lst[_])

Submission status: Accepted

Solution code:
from itertools import permutations
import sys
write = sys.stdout.write
N = int(sys.stdin.readline())
for p in permutations(map(str, range(1, N+1)), r=N):
    write(" ".join(p))
    write("\n")

Submission status: Accepted

Solution code:
n = int(input())
nl = [str(i) for i in range(1, n+1)]
def perm(nl):

    if len(nl) == 0:
        return []

    if len(nl) == 1:
        return [nl]

    l = []

    for i in range(len(nl)):

        m = nl[i]

        rest = nl[:i] + nl[i+1:]

        for p in perm(rest):
            l.append([m] + p)


    return l



for i in perm(nl):
    print(" ".join(i))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Permutation - Permutation Enumeration
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_5_D&lang=jp

"""
from itertools import permutations

for p in permutations(range(1, int(input())+1)):
    print(*p)

Submission status: Accepted

Solution code:
from itertools import permutations
for p in list(permutations(range(1, int(input())+1))): print(*p)

Submission status: Accepted

Solution code:
import itertools

if __name__ == '__main__':

	n = int(input())
	seq = list(itertools.permutations(range(1,n+1)))

	for p in seq:
		print(*p)

Submission status: Accepted

Solution code:
from itertools import permutations



# INPUT
n = int(input())


# PROCESS
str_num = ""

for num in range(1, n + 1):
    str_num += str(num)


# OUTPUT
for list_lexicographic_order in permutations(str_num):
    print(*list_lexicographic_order)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = tuple(range(1,n+1))
p = sorted(list(itertools.permutations(a)))
for i in p:
    print(*i)

Submission status: Accepted

Solution code:
def rec(lst,d):
    for i in range(1,len(lst)+1):
        if i not in lst:
            lst[d]  = i
            if d+1 == len(lst):
                a = list(lst)
                P.append(a)
                lst[d] = 0
                return
            else:
                rec(lst,d+1)
                lst[d] = 0

N = int(input())

P = []

lst = []
for i in range(N):
    lst.append(0)

rec(lst,0)

for i in range(len(P)):
    print(*P[i])

Submission status: Accepted

Solution code:
import itertools

n=int(input())
a=(i for i in range(1,n+1))
A=list(itertools.permutations(a))
for i in range(len(A)):
    print(' '.join(map(str,A[i])))

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_5_D&lang=jp
#  Permutation Enumeration : python3
#  2018.12.01 yonezawa

import sys
input = sys.stdin.readline
from collections import deque

class enumeration:
    def __init__(self,n):
        self.n = n
        self.depth = 0
        self.wnum = 0
        self.nq = []
        self.bits = [ pow(2,i) for i in range(n+1) ]
        self.mk_permutation(0,0,0)

    def mk_permutation(self,depth,bflag,wnum):
        if self.n == depth:
            self.nq.append(wnum)
            return
        for i in range(1,self.n+1):
            if bflag & self.bits[i-1] != 0:
                continue
            self.mk_permutation(depth + 1,bflag + self.bits[i-1],wnum*10+i)  
    def printList(self):
        l = self.nq
        self.nq.sort()
        for i in l:
            c = ""
            for j in str(i):
                c += j + " "
            print(c.strip())

def main():
    n = int(input())
    i = enumeration(n)
    i.printList()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import permutations
n = int(input())
p = permutations([str(x) for x in range(1, n+1)], n)
[print(' '.join(x)) for x in p]

Submission status: Accepted

Solution code:
import itertools

n = int(input())
num = [i for i in range(1, n+1)]

for per in itertools.permutations(num):
    print(' '.join(str(p) for p in per))

Submission status: Accepted

Solution code:
from itertools import permutations
n = int(input())
b = permutations(range(1, n+1))
for ele in b:
  print(" ".join(map(str, ele)))