aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/ask/lista11/gen.py
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-10-05 21:49:54 +0200
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-10-05 21:49:54 +0200
commitc5fcf7179a83ef65c86c6a4a390029149e518649 (patch)
treed29ffc5b86a0d257453cedcf87d91a13d8bf3b0d /Semestr 4/ask/lista11/gen.py
parentf8a88b6a4aba1f66d04711a9330eaba49a50c463 (diff)
Duzy commit ze smieciami
Diffstat (limited to 'Semestr 4/ask/lista11/gen.py')
-rw-r--r--Semestr 4/ask/lista11/gen.py65
1 files changed, 0 insertions, 65 deletions
diff --git a/Semestr 4/ask/lista11/gen.py b/Semestr 4/ask/lista11/gen.py
deleted file mode 100644
index d4de762..0000000
--- a/Semestr 4/ask/lista11/gen.py
+++ /dev/null
@@ -1,65 +0,0 @@
-def next_permutation(a):
- """Generate the lexicographically next permutation inplace.
-
- https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order
- Return false if there is no next permutation.
- """
- # Find the largest index i such that a[i] < a[i + 1]. If no such
- # index exists, the permutation is the last permutation
- for i in reversed(range(len(a) - 1)):
- if a[i] < a[i + 1]:
- break # found
- else: # no break: not found
- return False # no next permutation
-
- # Find the largest index j greater than i such that a[i] < a[j]
- j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])
-
- # Swap the value of a[i] with that of a[j]
- a[i], a[j] = a[j], a[i]
-
- # Reverse sequence from a[i + 1] up to and including the final element a[n]
- a[i + 1:] = reversed(a[i + 1:])
- return True
-
-def perm_to_str(a):
- return ''.join(map(str, a))
-
-def str_to_perm(s):
- return [int(c) for c in s]
-
-t = [0,1,2,3]
-perm_to_idx = dict()
-
-def bbin(x):
- return bin(x)[2:]
-
-cnt = 23
-while True:
- perm_to_idx[perm_to_str(t)] = cnt
- cnt -= 1
- if not next_permutation(t):
- break
-
-for p in perm_to_idx.keys():
- for i in range(4):
- t = str_to_perm(p)
- for j in range(4):
- if t[j] > t[i]:
- t[j] -= 1
- t[i] = 3
- print(p, 'x', i, '->', perm_to_str(t), ':\t', bbin(perm_to_idx[p]), '\t', bbin(i), '\t', bbin(perm_to_idx[perm_to_str(t)]), end='\t')
- print(perm_to_idx[p], '\t', i, '\t', perm_to_idx[perm_to_str(t)])
-
-print('\n-----\n')
-
-
-for p in perm_to_idx.keys():
- for i in range(4):
- t = str_to_perm(p)
- for j in range(4):
- if t[j] > t[i]:
- t[j] -= 1
- t[i] = 3
- print(p, 'x', i, '->', perm_to_str(t), ':\t', bbin(perm_to_idx[p]), '\t', bbin(i), '\t', bbin(perm_to_idx[perm_to_str(t)]), end='\t')
- print(perm_to_idx[p], '\t', i, '\t', perm_to_idx[perm_to_str(t)])