diff --git a/2024/05/06-05-24-Bonus/a.py b/2024/05/06-05-24-Bonus/a.py new file mode 100644 index 0000000..bec4353 --- /dev/null +++ b/2024/05/06-05-24-Bonus/a.py @@ -0,0 +1,48 @@ +import sys + +from munkres import Munkres + +m = Munkres() + +n, k = map(int, input().split()) + +ciphering = input() +sol = input() + +def from_letter(a): + if ord(a) < ord('a'): + return 26+ord(a)-ord('A') + return ord(a)-ord('a') + +def to_letter(n): + if n > 25: + return chr(n-26+ord('A')) + return chr(n+ord('a')) + +mat = [ + [0]*k for _ in range(k) +] + +for letter1, letter2 in zip(ciphering, sol): + mat[from_letter(letter1)][from_letter(letter2)] += 1 + + +cost_matrix = [] +for row in mat: + cost_row = [] + for col in row: + cost_row += [sys.maxsize - col] + cost_matrix += [cost_row] + +m = Munkres() +indexes = m.compute(cost_matrix) +total = 0 +for row, column in indexes: + value = mat[row][column] + total += value + +print(total) + +for row, column in indexes: + print(to_letter(column), end='') +print() diff --git a/2024/05/06-05-24-Bonus/a_fuzzing.py b/2024/05/06-05-24-Bonus/a_fuzzing.py new file mode 100644 index 0000000..8a40ea2 --- /dev/null +++ b/2024/05/06-05-24-Bonus/a_fuzzing.py @@ -0,0 +1,16 @@ +import random + +def to_letter(n): + if n > 25: + return chr(n-26+ord('A')) + return chr(n+ord('a')) + +n, k = 500000, 30 + +print(n, k) +for i in range(n): + print(to_letter(random.randint(0, k-1)), end="") +print() +for i in range(n): + print(to_letter(random.randint(0, k-1)), end="") +print() \ No newline at end of file