Permutation

Return all permutations of the input stream sorted in lexicographical order.

IN

123

OUT

123
132
213
231
312
321

IN

qwer

OUT

eqrw
eqwr
erqw
erwq
ewqr
ewrq
qerw
qewr
qrew
qrwe
qwer
qwre
reqw
rewq
rqew
rqwe
rweq
rwqe
weqr
werq
wqer
wqre
wreq
wrqe

IN

x

OUT

x
Login to submit solution


5 symbols pyth
Mon Sep 19 13:08:28 2016 Sait2000
j.pSz
42 symbols ruby2.0
Sun Oct 5 20:02:04 2014 fl00r
#!/usr/bin/ruby2.0 -n
puts$_.chars.permutation.sort.map &:join
46 symbols ruby2.0
Mon Sep 29 12:32:58 2014 vakorol
#!/usr/bin/ruby1.9.1 -n
puts$_.split(//).permutation.sort.map &:join
46 symbols ruby2.0
Sun Oct 5 19:58:37 2014 fl00r
#!/usr/bin/ruby2.0 -n
puts$_.split('').permutation.sort.map &:join
49 symbols ruby2.0
Fri Dec 27 01:50:54 2013 gsdstr
puts gets.chars.to_a.permutation.sort.map(&:join)
56 symbols haskell
Fri Mar 13 10:51:38 2015 YoshikuniJujo
import Data.List
main=interact$unlines.sort.permutations
67 symbols haskell
Fri Mar 13 10:50:22 2015 YoshikuniJujo
import Data.List
main=interact$unlines.sort.permutations.head.lines
69 symbols haskell
Fri Dec 27 00:01:28 2013 Anton Cheshkov
import Data.List
main=getContents>>=putStr.unlines.sort.permutations
78 symbols python3
Wed Sep 28 06:29:29 2016 Sait2000
from itertools import*
for p in permutations(sorted(input())):print(*p,sep='')
79 symbols python3
Mon Aug 11 16:05:37 2014 PFischbeck
from itertools import*
for p in sorted(permutations(input())):print(''.join(p))
79 symbols python3
Thu Sep 22 13:51:14 2016 Sait2000
from itertools import*
for p in permutations(sorted(input())):print(''.join(p))
80 symbols python2
Mon Aug 11 16:03:11 2014 PFischbeck
from itertools import*
for p in sorted(permutations(raw_input())):print`p`[2::5]
81 symbols python3
Thu Sep 22 13:56:17 2016 Sait2000
from itertools import*
any(map(print,map(''.join,permutations(sorted(input())))))
90 symbols python2
Mon Aug 11 13:47:21 2014 xsot
from itertools import*
print'\n'.join(`p`[2::5]for p in sorted(permutations(raw_input())))
90 symbols python2
Mon Aug 11 13:48:15 2014 xsot
from itertools import*
print`sorted(permutations(raw_input()))`.replace('(','\n   ')[6::5]
98 symbols python2
Fri Aug 8 13:40:55 2014 PFischbeck
from itertools import permutations as q
print"\n".join(''.join(p) for p in sorted(q(raw_input())))
164 symbols python3
Thu Feb 6 02:04:29 2014 maksim
from itertools import permutations
p = permutations(input(''))
l = [''.join([i for i in t]) for t in p]
l.sort()
o = ''
for s in l: o += s+'\n'
print(o[:-1],end='')
199 symbols python3
Thu Feb 6 02:03:09 2014 maksim
def p(s):
	l = []
	if len(s) > 1:
		for c in s: l.extend(c + i for i in p(s.replace(c,'')))
		return l
	else: return [s]
n = p(input(''))
n.sort()
o = ''
for i in n: o += i+'\n'
print(o[:-1],end='')
207 symbols python3
Wed Feb 5 23:27:37 2014 maksim
from itertools import permutations
l = []
p = permutations(input(''))
for t in p:
    s =''
    for i in range(len(t)): s += t[i]
    l.append(s)
l.sort()
o = ''
for s in l: o += s+'\n'
print(o[:-1],end='')
243 symbols python3
Wed Feb 5 21:33:19 2014 maksim
def p(s):
	l = []
	if len(s) > 2:
		for c in s: l.extend([c + i for i in p(s.replace(c,''))])
		return l
	elif len(s) == 2: return [s,s[::-1]]
	else: return s
n = p(input(''))
if len(n) > 1:
    n.sort()
    for i in n: print(i)
else: print(n)

View all solutions