Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
from itertools import permutations
|
||||
|
||||
in_order = lambda s: all(x <= s[i+1] for i,x in enumerate(s[:-1]))
|
||||
perm_sort = lambda s: (p for p in permutations(s) if in_order(p)).next()
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
from itertools import permutations
|
||||
from more_itertools import windowed
|
||||
|
||||
def is_sorted(seq):
|
||||
return all(
|
||||
v1 <= v2
|
||||
for v1, v2 in windowed(seq, 2)
|
||||
)
|
||||
|
||||
def permutation_sort(seq):
|
||||
return next(
|
||||
permutation
|
||||
for permutation in permutations(seq)
|
||||
if is_sorted(permutation)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue