Advertisement
DanikKUL

Алгоритм Рота в приложении

May 27th, 2022 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.33 KB | None | 0 0
  1. from math import floor
  2. from tkinter import *
  3. from tkinter import scrolledtext
  4. import random
  5.  
  6.  
  7. incorrect = 'ДОРОГУША МОЯ!'
  8. quotes = ['ОБ ЭТОМ Я ПОГОВОРЮ С ВАМИ НА СЕССИИ',
  9.           'Чистилище не за горами',
  10.           'Компиляторов начальник\n и АиЛОВТа командир',
  11.           'Верю во всевидящий ноль',
  12.           'КСиС, это выше, чем БГУИР',
  13.           'Деятельность: Люблю компилировать',
  14.           'Интересы: Отчислять студентов',
  15.           'Те, кто знают, могли бы\n предвосхитить, а я предупреждаю!',
  16.           'О себе:0,110101110101,010\n'
  17.           '11101010100010011011001 10101010110.\n'
  18.           '0101010100110111010110011010101101010101 ',
  19.           'Сессия - моя любимая пора...',
  20.           'Пройдемте на отчисление',
  21.           'У меня мозг десятичный\n'
  22.           'А че два показываете?\n'
  23.           'Мозг же десятичный',
  24.           'Программистов, как и разведчиков,\n'
  25.           ' бывших не бывает.',
  26.           'Каждый просто должен определиться с\n'
  27.           ' областью, где он Рембрандт.',
  28.           'Там двоичная система оценки:\n'
  29.           ' либо девять либо три.',
  30.           'Понимаете, на листочке бумаги с \n'
  31.           '“компилятором Луцик” легче разговаривать,\n'
  32.           ' чем с компилятором Microsoft.',
  33.           'Главное ― не оставляйте ничего на потом,\n потома не будет',
  34.           'Что тут непонятного, даже я понял']
  35.  
  36.  
  37. def clicked():
  38.     l_string = txt.get()
  39.     n_string = txt1.get()
  40.     if l_string == '':
  41.         lbl1.configure(text="Неверно введены значения")
  42.         label1.configure(text=incorrect)
  43.         return
  44.     for letter in l_string:
  45.         if letter != ' ' and letter != '0' and letter != '1' and letter != 'x':
  46.             lbl1.configure(text="Неверно введены значения")
  47.             label1.configure(text=incorrect)
  48.             return
  49.     for letter in n_string:
  50.         if letter != ' ' and letter != '0' and letter != '1' and letter != 'x':
  51.             lbl1.configure(text="Неверно введены значения")
  52.             label1.configure(text=incorrect)
  53.             return
  54.     l_list = l_string.split()
  55.     inp = len(l_list[0])
  56.     for elem in l_list:
  57.         if len(elem) != inp:
  58.             lbl1.configure(text="Неверно введены значения")
  59.             label1.configure(text=incorrect)
  60.             return
  61.     n_list = n_string.split()
  62.     for elem in n_list:
  63.         if len(elem) != inp:
  64.             lbl1.configure(text="Неверно введены значения")
  65.             label1.configure(text=incorrect)
  66.             return
  67.     for elem in l_list:
  68.         if elem in n_list:
  69.             lbl1.configure(text="Неверно введены значения")
  70.             label1.configure(text=incorrect)
  71.             return
  72.     lbl1.configure(text="Значения введены верно")
  73.     label1.configure(text=(quotes[floor(random.random() * 18)] + '\n' + "©BY LUCIK"))
  74.     try:
  75.         font_size = int(txt2.get())
  76.     except TypeError:
  77.         font_size = 10
  78.     scr_txt.configure(font=("Courier New", font_size),
  79.                       width=round(250 / font_size * 10),
  80.                       height=round(55 / font_size * 10))
  81.     print(150 / font_size, 55 / font_size)
  82.     rot_algo(l_list, n_list, inp)
  83.  
  84.  
  85. def rot_algo(array1, array2, inputs):
  86.     def multiplication(x1, x2):
  87.         res = []
  88.         for ind in range(len(x1)):
  89.             if x1[ind] == x2[ind]:
  90.                 res.append(x1[ind])
  91.             elif x1[ind] != x2[ind] and x1[ind] != 'x' and x2[ind] != 'x':
  92.                 res.append('y')
  93.             elif x1[ind] != x2[ind] and x1[ind] == 'x' and x2[ind] != 'x':
  94.                 res.append(x2[ind])
  95.             elif x1[ind] != x2[ind] and x1[ind] != 'x' and x2[ind] == 'x':
  96.                 res.append(x1[ind])
  97.         return ''.join(res)
  98.  
  99.     def multiplication_table(arr1, arr2):
  100.         res = []
  101.         for ind in range(len(arr2)):
  102.             res.append([])
  103.         for ind in range(len(arr2)):
  104.             for ind1 in range(len(arr1)):
  105.                 res[ind].append(multiplication(arr2[ind], arr1[ind1]))
  106.         string_null = '-' * inputs
  107.         for ind in range(len(arr2)):
  108.             ind1 = ind
  109.             while ind1 < len(arr1):
  110.                 res[ind][ind1] = string_null
  111.                 ind1 += 1
  112.         return res
  113.  
  114.     def get_set_a(mult_table, mini, maxim):
  115.         res = []
  116.         for ind in range(len(mult_table)):
  117.             for ind1 in range(len(mult_table[0])):
  118.                 counter = mult_table[ind][ind1].count('x') + mult_table[ind][ind1].count('y')
  119.                 if mult_table[ind][ind1].count('y') > 1:
  120.                     continue
  121.                 if maxim + 1 >= counter >= mini + 1:
  122.                     res.append(mult_table[ind][ind1])
  123.         for ind in range(len(res) - 1):
  124.             ind1 = ind + 1
  125.             while ind1 < len(res):
  126.                 if res[ind] == res[ind1]:
  127.                     res.pop(ind1)
  128.                 ind1 += 1
  129.         for ind in range(len(res)):
  130.             res[ind] = res[ind].replace('y', 'x')
  131.         return res
  132.  
  133.     def get_set_b(set_c, set_z):
  134.         res = []
  135.         for ind in set_c:
  136.             if ind not in set_z:
  137.                 res.append(ind)
  138.         return res
  139.  
  140.     def get_set_z(mult_table, set_c, set_a):
  141.         set_z = []
  142.         for ind in range(len(mult_table[0])):
  143.             new_arr_x = []
  144.             new_arr_y = []
  145.             for ind1 in range(len(mult_table)):
  146.                 if mult_table[ind1][ind].count('y') < 2:
  147.                     new_arr_y.append(mult_table[ind1][ind].replace('y', 'x'))
  148.                 else:
  149.                     new_arr_y.append('-' * inputs)
  150.             for ind1 in range(len(mult_table[0])):
  151.                 if mult_table[ind][ind1].count('y') < 2:
  152.                     new_arr_x.append(mult_table[ind][ind1].replace('y', 'x'))
  153.                 else:
  154.                     new_arr_x.append("-" * inputs)
  155.             flag = False
  156.             for ind2 in range(len(set_a)):
  157.                 if set_a[ind2] in new_arr_x:
  158.                     flag = True
  159.                 if set_a[ind2] in new_arr_y:
  160.                     flag = True
  161.             if not flag:
  162.                 set_z.append(set_c[ind])
  163.         return set_z
  164.  
  165.     def maximum(arr):
  166.         res = 0
  167.         for item in arr:
  168.             cur = item.count('x')
  169.             if cur > res:
  170.                 res = cur
  171.         return res
  172.  
  173.     def minimum(arr):
  174.         res = 10
  175.         for item in arr:
  176.             cur = item.count('x')
  177.             if cur < res:
  178.                 res = cur
  179.         return res
  180.  
  181.     def are_same(x1, x2):
  182.         for ind in range(len(x1)):
  183.             if x1[ind] == x2[ind] or x2[ind] == 'x':
  184.                 continue
  185.             else:
  186.                 return False
  187.         return True
  188.  
  189.     def unite_sets(arr1, arr2):
  190.         res = []
  191.         for ind in range(len(arr1)):
  192.             flag = False
  193.             for ind1 in range(len(arr2)):
  194.                 if are_same(arr1[ind], arr2[ind1]):
  195.                     flag = True
  196.             if not flag:
  197.                 res.append(arr1[ind])
  198.  
  199.         for ind in arr2:
  200.             res.append(ind)
  201.         return res
  202.  
  203.     def additional_cubes(set_c, set_z, amount):
  204.         res = []
  205.         ind = 0
  206.         while ind < len(set_z):
  207.             if len(set_z) < ind or len(set_c) < ind:
  208.                 break
  209.             if amount == set_z[ind].count('x') and set_z[ind] in set_c:
  210.                 res.append(set_z[ind])
  211.                 set_z.pop(ind)
  212.             ind += 1
  213.         return res
  214.  
  215.     def delete_duplicates(arr):
  216.         new_arr = []
  217.         for item in arr:
  218.             if item not in new_arr:
  219.                 new_arr.append(item)
  220.         return new_arr
  221.  
  222.     print("\nЭТАП УМНОЖЕНИЯ КУБОВ (C * C)\n")
  223.     dashes = '-' * inputs
  224.     scr_txt.delete(0.0, END)
  225.     scr_txt.insert(INSERT, "ЭТАП УМНОЖЕНИЯ КУБОВ (C * C)\n")
  226.     set_a1 = [0]
  227.     set_c1 = unite_sets(array1, array2)
  228.     minim = minimum(set_c1) + 1
  229.     cubes = []
  230.     full_set_z = []
  231.     while set_a1:
  232.         table = multiplication_table(set_c1, set_c1 + cubes)
  233.         print("\nРезультат умножения")
  234.         scr_txt.insert(INSERT, "\nРезультат умножения\n")
  235.         print("-" * inputs, set_c1)
  236.         tmp_str = ' '.join(set_c1)
  237.         scr_txt.insert(INSERT, ' ' + dashes)
  238.         scr_txt.insert(INSERT, '| ' + tmp_str)
  239.         scr_txt.insert(INSERT, '\n')
  240.         am = 0
  241.         for i in range(len(table)):
  242.             if len(set_c1) > i:
  243.                 print(set_c1[i], table[i])
  244.                 scr_txt.insert(INSERT, ' ' + set_c1[i])
  245.                 tmp_str = ' '.join(table[i])
  246.                 scr_txt.insert(INSERT, '| ' + tmp_str)
  247.                 scr_txt.insert(INSERT, '\n')
  248.             else:
  249.                 print(cubes[am], table[i])
  250.                 scr_txt.insert(INSERT, ' ' + cubes[am])
  251.                 tmp_str = ' '.join(table[i])
  252.                 scr_txt.insert(INSERT, '| ' + tmp_str)
  253.                 scr_txt.insert(INSERT, '\n')
  254.                 am += 1
  255.         set_a1 = delete_duplicates(get_set_a(table, minimum(set_c1), maximum(set_c1)))
  256.         print("\nМножество А:", set_a1)
  257.         tmp_str = ' '.join(set_a1)
  258.         scr_txt.insert(INSERT, '\nМножество А:' + tmp_str + '\n')
  259.         if not set_a1:
  260.             full_set_z += cubes
  261.         set_z1 = delete_duplicates(get_set_z(table, set_c1, set_a1))
  262.         print("\nМножество Z:", set_z1)
  263.         tmp_str = ' '.join(set_z1)
  264.         scr_txt.insert(INSERT, '\nМножество Z:' + tmp_str + '\n')
  265.         set_b1 = delete_duplicates(get_set_b(set_c1, set_z1))
  266.         print("\nМножество B:", set_b1)
  267.         tmp_str = ' '.join(set_b1)
  268.         scr_txt.insert(INSERT, '\nМножество B:' + tmp_str + '\n')
  269.         cubes = delete_duplicates(additional_cubes(set_c1, set_z1, minim))
  270.         print("\nДополнительные кубы:", cubes)
  271.         tmp_str = ' '.join(cubes)
  272.         scr_txt.insert(INSERT, '\nДополнительные кубы:' + tmp_str + '\n')
  273.         set_c1 = delete_duplicates(unite_sets(set_b1, set_a1))
  274.         print("\nМножество C:", set_c1)
  275.         tmp_str = ' '.join(set_c1)
  276.         scr_txt.insert(INSERT, '\nМножество C:' + tmp_str + '\n')
  277.         full_set_z += set_z1
  278.         minim += 1
  279.         scr_txt.insert(INSERT, '\n\n\n')
  280.     full_set_z = delete_duplicates(full_set_z)
  281.     print("\nКонечное множество Z:", full_set_z)
  282.     tmp_str = ' '.join(full_set_z)
  283.     scr_txt.insert(INSERT, '\nКонечное множество Z:' + tmp_str + '\n')
  284.     review = []
  285.  
  286.     def substraction(set_z):
  287.         result = []
  288.         x = []
  289.         for ind in range(len(set_z)):
  290.             print("\nСледующее вычитание:", set_z[ind])
  291.             scr_txt.insert(INSERT, "\nСледующее вычитание: " + set_z[ind] + '\n')
  292.             tmp = set_z[ind]
  293.             for ind1 in range(len(set_z)):
  294.                 if ind == ind1:
  295.                     continue
  296.                 else:
  297.                     x = sub(tmp, set_z[ind1])
  298.                     print("Остаток:", x)
  299.                     if x[0] is None:
  300.                         tmp_st = 'Нет остатка'
  301.                     else:
  302.                         tmp_st = ' '.join(x)
  303.                     scr_txt.insert(INSERT, "Остаток: " + tmp_st + '\n')
  304.                     if len(x) == 1:
  305.                         if x[0] is None:
  306.                             break
  307.                         else:
  308.                             tmp = x[0]
  309.                     else:
  310.                         buff = x
  311.                         for ind3 in range(len(x)):
  312.                             ind2 = ind1
  313.                             tmp = buff[ind3]
  314.                             while ind2 < len(set_z):
  315.                                 if x[0] is None:
  316.                                     break
  317.                                 if ind2 == ind:
  318.                                     ind2 += 1
  319.                                     continue
  320.                                 if ind3 >= len(x):
  321.                                     break
  322.                                 x = sub(tmp, set_z[ind2])
  323.                                 tmp = x[ind3]
  324.                                 ind2 += 1
  325.                             if x[0] is not None:
  326.                                 review.append([x, ind])
  327.                             result += x
  328.             print(x)
  329.             if x and x[0] is not None:
  330.                 review.append([x, ind])
  331.             result += x
  332.         return result
  333.  
  334.     def replacer(s, newstring, index, nofail=False):
  335.         if not nofail and index not in range(len(s)):
  336.             raise ValueError("index outside given string")
  337.         if index < 0:
  338.             return newstring + s
  339.         if index > len(s):
  340.             return s + newstring
  341.         return s[:index] + newstring + s[index + 1:]
  342.  
  343.     def sub(x1, x2):
  344.         print("Дано:", x1, "#", x2)
  345.         scr_txt.insert(INSERT, "Дано:" + x1 + '#' + x2 + '\n')
  346.         res = []
  347.         for ind in range(len(x1)):
  348.             if x1[ind] == x2[ind]:
  349.                 res.append('z')
  350.             elif x1[ind] != x2[ind] and x1[ind] == 'x':
  351.                 if x2[ind] == '0':
  352.                     res.append('1')
  353.                 else:
  354.                     res.append('0')
  355.             elif x1[ind] != x2[ind] and x2[ind] == 'x':
  356.                 res.append('z')
  357.             else:
  358.                 res.append('y')
  359.         print("Результат вычитания:", ''.join(res))
  360.         scr_txt.insert(INSERT, "Результат вычитания:" + ''.join(res) + '\n')
  361.         if 'y' in res:
  362.             return [x1]
  363.         count_nums = 0
  364.         count_z = 0
  365.         for ind in res:
  366.             if ind == 'z':
  367.                 count_z += 1
  368.             elif ind == '1' or ind == '0':
  369.                 count_nums += 1
  370.         if count_z == len(res):
  371.             return [None]
  372.         else:
  373.             ret = []
  374.             prev_ind = 0
  375.             for ind in range(count_nums):
  376.                 tmp = x1
  377.                 ret.append([])
  378.                 ind1 = prev_ind
  379.                 while ind1 < len(tmp):
  380.                     if res[ind1] == '1':
  381.                         tmp = replacer(tmp, '1', ind1)
  382.                         ret[ind].append(tmp)
  383.                         prev_ind = ind1 + 1
  384.                         break
  385.                     elif res[ind1] == '0':
  386.                         tmp = replacer(tmp, '0', ind1)
  387.                         ret[ind].append(tmp)
  388.                         prev_ind = ind1 + 1
  389.                         break
  390.                     ind1 += 1
  391.             return sum(ret, [])
  392.  
  393.     def get_set_e(rev, set_z):
  394.         set_e = []
  395.         for ind in range(len(rev)):
  396.             set_e.append(set_z[rev[ind][1]])
  397.         return set_e
  398.  
  399.     print("\nВЫЧИТАНИЕ КУБОВ (z#(Z-z))\n")
  400.     scr_txt.insert(INSERT, "\nВЫЧИТАНИЕ КУБОВ (z#(Z-z))\n" + '\n')
  401.     subs_set = delete_duplicates(substraction(full_set_z))
  402.     i = 0
  403.     while i < len(subs_set):
  404.         if subs_set[i] is None:
  405.             i -= 1
  406.             subs_set.remove(None)
  407.         i += 1
  408.     review = delete_duplicates(review)
  409.     print("\nМножество Z:", full_set_z)
  410.     tmp_str = ' '.join(full_set_z)
  411.     scr_txt.insert(INSERT, "\nМножество Z:" + tmp_str + '\n')
  412.     print("\nОстатки с индексами:", review)
  413.     set_e1 = delete_duplicates(get_set_e(review, full_set_z))
  414.     print("\nМножество Е:", set_e1)
  415.     tmp_str = ' '.join(set_e1)
  416.     scr_txt.insert(INSERT, "\nМножество E:" + tmp_str + '\n')
  417.  
  418.     def table_intersection(set_l, set_rem):
  419.         res = []
  420.         for ind in range(len(set_l)):
  421.             res.append([])
  422.         for ind in range(len(set_l)):
  423.             for ind1 in range(len(set_rem)):
  424.                 res[ind].append(intersection(set_l[ind], set_rem[ind1][0][0]))
  425.         return res
  426.  
  427.     def intersection(x1: str, x2: str):
  428.         res = []
  429.         for ind in range(len(x1)):
  430.             if x1[ind] != x2[ind] and x1[ind] != 'x' and x2[ind] != 'x':
  431.                 return None
  432.             elif x1[ind] == x2[ind]:
  433.                 res.append(x1[ind])
  434.             elif x1[ind] != x2[ind] and x1[ind] == 'x':
  435.                 if x2[ind] == '1':
  436.                     res.append('1')
  437.                 elif x2[ind] == '0':
  438.                     res.append('0')
  439.             elif x1[ind] != x2[ind] and x2[ind] == 'x':
  440.                 if x1[ind] == '1':
  441.                     res.append('1')
  442.                 elif x1[ind] == '0':
  443.                     res.append('0')
  444.         return ''.join(res)
  445.  
  446.     def ret_same(x1, x2):
  447.         res = []
  448.         for ind in range(len(x1)):
  449.             if x1[ind] == x2[ind] or x2[ind] == 'x' or x1[ind] == 'x':
  450.                 res.append(x1[ind])
  451.             else:
  452.                 return False
  453.         return ''.join(res)
  454.  
  455.     def get_rest(set_rem, rem, set_z):
  456.         res = []
  457.         for ind in range(len(set_rem)):
  458.             for ind1 in range(len(rem)):
  459.                 if ret_same(rem[ind1], set_rem[ind][0][0]):
  460.                     res.append(set_z[set_rem[ind][1]])
  461.                     continue
  462.         return res
  463.  
  464.     print("\nПЕРЕСЕЧЕНИЕ КУБОВ (z#(Z - z) ⋂ L)\n")
  465.     scr_txt.insert(INSERT, "\nПЕРЕСЕЧЕНИЕ КУБОВ (z#(Z - z) ⋂ L)\n" + '\n')
  466.     table1 = table_intersection(array1, review)
  467.     rem1 = []
  468.     for i in range(len(table1)):
  469.         for j in range(len(table1[0])):
  470.             if table1[i][j] is not None:
  471.                 rem1.append(table1[i][j])
  472.     print("\nТаблица пересечения:")
  473.     scr_txt.insert(INSERT, "\nТаблица пересечения:" + '\n')
  474.     for i in range(len(table1)):
  475.         print(array1[i], table1[i])
  476.         tmp_str = ''
  477.         for item in table1[i]:
  478.             if item is None:
  479.                 tmp_str += "None "
  480.             else:
  481.                 tmp_str += item + ' '
  482.         scr_txt.insert(INSERT, array1[i] + '| ' + tmp_str + '\n')
  483.     set_e1 = delete_duplicates(get_rest(review, rem1, full_set_z))
  484.     print("\nМножество Е:", set_e1)
  485.     tmp_str = ' '.join(set_e1)
  486.     scr_txt.insert(INSERT, "\nМножество Е:" + tmp_str + '\n')
  487.  
  488.     def substraction1(set_l, set_e):
  489.         result = []
  490.         x = []
  491.         for ind in range(len(set_l)):
  492.             print("\nСледующее вычитание:", set_l[ind])
  493.             scr_txt.insert(INSERT, "\nСледующее вычитание: " + set_l[ind] + '\n')
  494.             tmp = set_l[ind]
  495.             for ind1 in range(len(set_e)):
  496.                 x = sub(tmp, set_e[ind1])
  497.                 print("Остаток:", x)
  498.                 if x[0] is None:
  499.                     tmp_st = 'Нет остатка'
  500.                 else:
  501.                     tmp_st = ' '.join(x)
  502.                 scr_txt.insert(INSERT, "Остаток: " + tmp_st + '\n')
  503.                 if len(x) == 1:
  504.                     if x[0] is None:
  505.                         break
  506.                     else:
  507.                         tmp = x[0]
  508.                 else:
  509.                     buff = x
  510.                     for m in range(len(x)):
  511.                         k = ind1
  512.                         tmp = buff[m]
  513.                         while k < len(set_e):
  514.                             if x[0] is None:
  515.                                 break
  516.                             if m >= len(x):
  517.                                 break
  518.                             x = sub(tmp, set_e[k])
  519.                             tmp = x[m]
  520.                             k += 1
  521.                         if x[0] is not None:
  522.                             review.append([x, ind])
  523.                         result += x
  524.             if x and x[0] is not None:
  525.                 review.append([x, ind])
  526.             result += x
  527.         return result
  528.  
  529.     def get_uncovered_set(uncovered):
  530.         res = []
  531.         for item in uncovered:
  532.             if item is not None:
  533.                 res.append(item)
  534.         return res
  535.  
  536.     uncovered_set = get_uncovered_set(substraction1(array1, set_e1))
  537.     print("\nНепокрытые остатки:", uncovered_set)
  538.     if not uncovered_set:
  539.         tmp_st = 'Нет непокрытых остатков'
  540.     elif uncovered_set[0] is None:
  541.         tmp_st = 'Нет непокрытых остатков'
  542.     else:
  543.         tmp_st = ' '.join(uncovered_set)
  544.     scr_txt.insert(INSERT, "\nНепокрытые остатки: " + tmp_st + '\n')
  545.  
  546.     def get_new_set_z(set_z, set_e):
  547.         res = []
  548.         for item in set_z:
  549.             if item not in set_e:
  550.                 res.append(item)
  551.         return res
  552.  
  553.     def table_intersection1(set_l, set_rem):
  554.         res = []
  555.         for ind in range(len(set_l)):
  556.             res.append([])
  557.         for ind in range(len(set_l)):
  558.             for ind1 in range(len(set_rem)):
  559.                 res[ind].append(intersection(set_l[ind], set_rem[ind1]))
  560.         return res
  561.  
  562.     print("\nПЕРЕСЕЧЕНИЕ МНОЖЕСТВА Z И ОСТАТКОВ\n")
  563.     scr_txt.insert(INSERT, "\nПЕРЕСЕЧЕНИЕ МНОЖЕСТВА Z И ОСТАТКОВ\n " + '\n')
  564.     full_set_z = get_new_set_z(full_set_z, set_e1)
  565.     print("Новое множество Z", full_set_z, "\n")
  566.     tmp_str = ' '.join(full_set_z)
  567.     scr_txt.insert(INSERT, "Новое множество Z: " + tmp_str + '\n')
  568.     table = table_intersection1(full_set_z, uncovered_set)
  569.     print('-' * inputs, uncovered_set)
  570.     tmp_str = ' '.join(uncovered_set)
  571.     scr_txt.insert(INSERT, dashes + '| ' + tmp_str + '\n')
  572.     for i in range(len(table)):
  573.         print(full_set_z[i], table[i])
  574.         tmp_str = ''
  575.         for item in table[i]:
  576.             if item is None:
  577.                 tmp_str += "None "
  578.             else:
  579.                 tmp_str += item + ' '
  580.         scr_txt.insert(INSERT, full_set_z[i] + '| ' + tmp_str + '\n')
  581.     print("\nМножество Е:", set_e1)
  582.     tmp_str = ' '.join(set_e1)
  583.     scr_txt.insert(INSERT, "\nМножество Е:" + tmp_str + '\n')
  584.     func_list = []
  585.  
  586.     def get_func(tab, ind2, arr, iml):
  587.         if ind2 >= len(tab[0]):
  588.             tmp = []
  589.             for x in arr:
  590.                 tmp.append(x)
  591.             func_list.append(tmp)
  592.             return
  593.         for ind in range(len(tab)):
  594.             if tab[ind][ind2] is not None:
  595.                 arr.append(iml[ind])
  596.                 get_func(tab, ind2 + 1, arr, iml)
  597.                 arr.pop()
  598.  
  599.     out = []
  600.     if table:
  601.         get_func(table, 0, out, full_set_z)
  602.  
  603.     if not set_e1:
  604.         set_e1 = full_set_z
  605.  
  606.     for i in range(len(func_list)):
  607.         func_list[i] = delete_duplicates(func_list[i])
  608.  
  609.     for i in range(len(func_list)):
  610.         for j in range(len(set_e1)):
  611.             func_list[i].append(set_e1[j])
  612.  
  613.     flag = False
  614.     if not func_list:
  615.         flag = True
  616.         func_list.append([])
  617.         for i in range(len(set_e1)):
  618.             func_list[0].append(set_e1[i])
  619.  
  620.     for i in range(len(func_list)):
  621.         for j in range(len(func_list[i])):
  622.             string = ''
  623.             for k in range(len(func_list[i][j])):
  624.                 if func_list[i][j][k] == '0':
  625.                     string += ''.join('!' + f'x{k + 1}')
  626.                 elif func_list[i][j][k] == '1':
  627.                     string += ''.join(f'x{k + 1}')
  628.             func_list[i][j] = string
  629.  
  630.     print("\nИТОГОВЫЕ ФУНКЦИИ\n")
  631.     scr_txt.insert(INSERT, "\nИТОГОВЫЕ ФУНКЦИИ\n" + '\n')
  632.  
  633.     print(func_list)
  634.     if not flag:
  635.         for i in range(len(func_list)):
  636.             string = ''
  637.             for j in range(len(func_list[i])):
  638.                 if j != len(func_list[i]):
  639.                     string += ''.join(func_list[i][j] + ' v ')
  640.                 else:
  641.                     string += ''.join(func_list[i][j])
  642.             if string and string[-2] == 'v':
  643.                 string = string[:-2]
  644.             print(f"F{i + 1} =", string)
  645.             scr_txt.insert(INSERT, f"\n\nF{i + 1} =" + ' ' + string + '\n')
  646.     else:
  647.         string = 'F = '
  648.         for i in range(len(func_list[0])):
  649.             if i + 1 != len(func_list[0]):
  650.                 string += ''.join(func_list[0][i] + ' v ')
  651.             else:
  652.                 string += ''.join(func_list[0][i])
  653.         scr_txt.insert(INSERT, '\n' + string + '\n')
  654.         print(string)
  655.  
  656.  
  657. window = Tk()
  658. window.state('zoomed')
  659. window.title("Rot's Algorithm")
  660. window.configure(background="#2e3032")
  661. lbl = Label(window,
  662.             text="Алгоритм Рота",
  663.             font=("Arial Bold", 30),
  664.             height=1, width=14,
  665.             background="#2e3032",
  666.             foreground='white')
  667. lbl.place(x=20, y=0)
  668. lbl = Label(window,
  669.             text="Введите данные в таком формате",
  670.             font=("Arial Bold", 13),
  671.             height=1,
  672.             width=29,
  673.             background="#2e3032",
  674.             foreground='white')
  675. lbl.place(x=20, y=40)
  676. lbl = Label(window,
  677.             text="00x00 1x111 xx101 00010",
  678.             font=("Courier New", 15),
  679.             height=1,
  680.             width=22,
  681.             background="#202020",
  682.             foreground='white')
  683. lbl.place(x=23, y=70)
  684. lbl = Label(window,
  685.             text="L-наборы",
  686.             font=("Arial Bold", 15),
  687.             height=1,
  688.             width=12,
  689.             background="#2e3032",
  690.             foreground='white')
  691. lbl.place(x=20, y=120)
  692. txt = Entry(window,
  693.             width=25,
  694.             font=("Courier New", 14),
  695.             background="#202020",
  696.             foreground='white')
  697. txt.place(x=20, y=150)
  698. lbl = Label(window,
  699.             text="N-наборы",
  700.             font=("Arial Bold", 15),
  701.             height=1,
  702.             width=12,
  703.             background="#2e3032",
  704.             foreground='white')
  705. lbl.place(x=20, y=190)
  706. txt1 = Entry(window,
  707.              width=25,
  708.              font=("Courier New", 14),
  709.              background="#202020",
  710.              foreground="white")
  711. txt1.place(x=20, y=220)
  712. lbl1 = Label(window,
  713.              text="",
  714.              font=("Arial Bold", 15),
  715.              height=1,
  716.              width=24,
  717.              background="#2e3032",
  718.              foreground='white')
  719. lbl1.place(x=20, y=330)
  720. lbl2 = Label(window,
  721.              text="Размер шрифта",
  722.              font=("Arial Bold", 15),
  723.              height=1,
  724.              width=14,
  725.              background="#2e3032",
  726.              foreground='white')
  727. lbl2.place(x=20, y=264)
  728. txt2 = Entry(window,
  729.              width=6,
  730.              background="#202020",
  731.              foreground="white")
  732. txt2.place(x=191, y=263)
  733. txt2.insert(INSERT, '10')
  734. btn = Button(window,
  735.              text="Готово",
  736.              font=("Arial Bold", 15),
  737.              height=1,
  738.              width=22,
  739.              command=clicked,
  740.              background='#202020',
  741.              foreground='white',
  742.              activebackground='#202020',
  743.              bg="gray",
  744.              fg="black",
  745.              relief="ridge")
  746. btn.place(x=21, y=360)
  747. font_size = 10
  748. scr_txt = scrolledtext.ScrolledText(window,
  749.                                     width=round(250 / font_size * 10),
  750.                                     height=round(55 / font_size * 10),
  751.                                     font=("Courier New", 10),
  752.                                     background='#202020',
  753.                                     foreground='white')
  754. scr_txt.place(x=280, y=0)
  755. scr_txt.insert(INSERT, 'Здесь будет решение')
  756. label1 = Label(window,
  757.                text='ОБ ЭТОМ Я ПОГОВОРЮ С ВАМИ НА СЕССИИ',
  758.                font=("Arial Bold", 10),
  759.                foreground='white',
  760.                background='#2e3032')
  761. label1.place(x=20, y=400)
  762. window.mainloop()
  763.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement