mirror of
https://github.com/iritmaximus/tira.git
synced 2026-10-12 19:13:47 +03:00
33 lines
683 B
Python
33 lines
683 B
Python
def create(s):
|
|
global not_used, result
|
|
not_used = []
|
|
result = []
|
|
not_used = [x for x in s]
|
|
haku(0, len(s), sorted(s))
|
|
print()
|
|
return sorted(result)
|
|
|
|
|
|
def haku(k, n, s):
|
|
print(s, not_used)
|
|
list = []
|
|
|
|
if k == n:
|
|
print(list)
|
|
result.append("".join(list))
|
|
else:
|
|
for i, x in enumerate(s):
|
|
|
|
if x not in not_used:
|
|
not_used.remove(x)
|
|
list.append(x)
|
|
|
|
haku(k + 1, n, s)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(create("ab")) # [ab,ba]
|
|
print(create("abac"))
|
|
# [aabc,aacb,abac,abca,acab,acba,baac,baca,bcaa,caab,caba,cbaa]
|
|
print(len(create("aybabtu"))) # 1260
|