Advertisement
100hahahaha

Untitled

May 29th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.29 KB | None | 0 0
  1. import time
  2.  
  3. AX = [False, False, False, False, False, False, False]
  4. Yarr = [False, False, False, False, False, False, False, False, False, False]
  5. STATES = ['SO', 'S1', 'S2', 'S3', 'S4', 'S5']
  6. used = []
  7. cycle = False
  8.  
  9. # множества единичных наборов
  10. y1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  11. y2 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
  12. y3 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
  13. y4 = [40, 41, 42, 43, 44, 45, 46, 47]
  14. y5 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
  15. y6 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
  16. y7 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
  17. y8 = [70, 71, 78, 79]
  18. y9 = [81, 83, 85, 87, 89, 91, 93, 95]
  19. y10 = [68, 69, 76, 77]
  20. w1 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
  21. w2 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 64, 65, 66, 67, 73, 74, 75, 72]
  22. w3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 40, 41, 42, 43, 44, 45, 46, 47, 32, 33, 34, 35, 36, 37,
  23.       38, 39, 70, 71, 78, 79]
  24. u1 = [68, 69, 77, 76, 64, 65, 66, 67, 73, 74, 75, 72, 81, 83, 85, 87, 89, 91, 93, 95, 80, 82, 84, 86, 88, 90, 92,
  25.       94]
  26. u2 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
  27. u3 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 81, 83, 85, 87, 89, 91, 93, 95, 80, 82, 84,
  28.       86, 88, 90, 92, 94, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
  29.  
  30.  
  31. def set_null():
  32.     Yarr = [False, False, False, False, False, False, False, False, False, False]
  33.  
  34.  
  35. # определение индекса текущего состояния
  36. def get_state():
  37.     index = 0
  38.     if AX[0]:
  39.         index += 4
  40.     if AX[1]:
  41.         index += 2
  42.     if AX[2]:
  43.         index += 1
  44.     return index
  45.  
  46.  
  47. def setSYbyLogic():
  48.     Yarr[0] = not AX[0] and not AX[1] and not AX[2]
  49.     Yarr[1] = Yarr[2] = not AX[0] and not AX[1] and AX[2]
  50.     Yarr[3] = not AX[0] and AX[1] and not AX[2] and AX[3]
  51.     Yarr[4] = Yarr[5] = Yarr[6] = not AX[0] and AX[1] and AX[2]
  52.     Yarr[7] = AX[0] and not AX[1] and not AX[2] and AX[4] and AX[5]
  53.     Yarr[8] = AX[0] and not AX[1] and AX[2] and AX[6]
  54.     Yarr[9] = AX[0] and not AX[1] and not AX[2] and AX[4] and not AX[5]
  55.  
  56.     W = [False, False, False]
  57.     U = [False, False, False]
  58.  
  59.     W[0] = not AX[0] and AX[1] and AX[2]
  60.  
  61.     W[1] = not AX[0] and not AX[1] and AX[2] or \
  62.            AX[0] and not AX[1] and not AX[2] and not AX[4]
  63.  
  64.     W[2] = not AX[0] and not AX[1] and not AX[2] or \
  65.            not AX[0] and AX[1] and not AX[2] and AX[3] or \
  66.            not AX[0] and AX[1] and not AX[2] and not AX[3] or \
  67.            AX[0] and not AX[1] and not AX[2] and AX[4] and AX[5]
  68.  
  69.     U[0] = AX[0] and not AX[1] and not AX[2] and not AX[4] or \
  70.            AX[0] and AX[1] and AX[2] and AX[4] and not AX[5] or \
  71.            AX[0] and not AX[1] and AX[2] and not AX[6] or \
  72.            AX[0] and not AX[1] and AX[2] and AX[6] or \
  73.            AX[0] and not AX[1] and not AX[2] and AX[4] and not AX[5]
  74.  
  75.     U[1] = not AX[0] and AX[1] and AX[2]
  76.  
  77.     U[2] = not AX[0] and not AX[1] and AX[2] or \
  78.            not AX[0] and AX[1] and AX[2] or \
  79.            AX[0] and not AX[1] and AX[2] and not AX[6] or \
  80.            AX[0] and not AX[1] and AX[2] and AX[6] or \
  81.            AX[0] and AX[1] and AX[2] and AX[4] and not AX[5]
  82.  
  83.     for i in range(3):
  84.         if W[i]:
  85.             AX[i] = True
  86.         if U[i]:
  87.             AX[i] = False
  88.  
  89.  
  90. def setSYbyBinSets(num):
  91.     if num in y1:
  92.         Yarr[0] = True
  93.     else:
  94.         Yarr[0] = False
  95.     if num in y2:
  96.         Yarr[1] = True
  97.     else:
  98.         Yarr[1] = False
  99.     if num in y3:
  100.         Yarr[2] = True
  101.     else:
  102.         Yarr[2] = False
  103.     if num in y4:
  104.         Yarr[3] = True
  105.     else:
  106.         Yarr[3] = False
  107.     if num in y5:
  108.         Yarr[4] = True
  109.     else:
  110.         Yarr[4] = False
  111.     if num in y6:
  112.         Yarr[5] = True
  113.     else:
  114.         Yarr[5] = False
  115.     if num in y7:
  116.         Yarr[6] = True
  117.     else:
  118.         Yarr[6] = False
  119.     if num in y8:
  120.         Yarr[7] = True
  121.     else:
  122.         Yarr[7] = False
  123.     if num in y9:
  124.         Yarr[8] = True
  125.     else:
  126.         Yarr[8] = False
  127.     if num in y10:
  128.         Yarr[9] = True
  129.     else:
  130.         Yarr[9] = False
  131.  
  132.     if num in w1:
  133.         AX[0] = True
  134.     if num in u1:
  135.         AX[0] = False
  136.     if num in w2:
  137.         AX[1] = True
  138.     if num in u2:
  139.         AX[1] = False
  140.     if num in w3:
  141.         AX[2] = True
  142.     if num in u3:
  143.         AX[2] = False
  144.  
  145.  
  146. if __name__ == "__main__":
  147.     for i in range(4):
  148.         ch = input(f"Введите x{i + 1}: ")
  149.         if ch == '1':
  150.             AX[i + 3] = True
  151.         else:
  152.             AX[i + 3] = False
  153.     method = input("введите режим работы:\n1 - логические выражения;\n2 - множество единичных наборов;\n")
  154.     if method == '1':
  155.         print("S(НАЧ) -> Yarr (y1-y10) -> S(КОН)")
  156.         start = time.perf_counter()
  157.         used.append(0)
  158.         while not cycle:
  159.             ind = get_state()
  160.             print(STATES[ind], end=" -> ")
  161.             setSYbyLogic()
  162.             for y in Yarr:
  163.                 if y:
  164.                     print('1', end="")
  165.                 else:
  166.                     print('0', end="")
  167.             ind = get_state()
  168.             print(f" -> {STATES[ind]}")
  169.             if ind in used and ind != 0:
  170.                 print("!!!программа ЗАЦИКЛИЛАСЬ!!!")
  171.                 cycle = True
  172.                 stop = time.perf_counter()
  173.                 print(f"\nВремя работы: {stop - start} секунд")
  174.             elif ind == 0:
  175.                 print("!!!программа ЗАВЕРШИЛАСЬ!!!")
  176.                 stop = time.perf_counter()
  177.                 print(f"\nВремя работы: {stop - start} секунд")
  178.                 cycle = True
  179.             else:
  180.                 used.append(ind)
  181.             set_null()
  182.     elif method == '2':
  183.         print("S(НАЧ) -> Yarr (y1-y10) -> S(КОН)")
  184.         start2 = time.perf_counter()
  185.         used.append(0)
  186.         while not cycle:
  187.             ind = get_state()
  188.             print(STATES[ind], end=" -> ")
  189.             mpow = 6
  190.             num = 0
  191.             for i in AX:
  192.                 if i:
  193.                     num += 2 ** mpow
  194.                 mpow -= 1
  195.             setSYbyBinSets(num)
  196.             for y in Yarr:
  197.                 if y:
  198.                     print('1', end="")
  199.                 else:
  200.                     print('0', end="")
  201.             ind = get_state()
  202.             print(f" -> {STATES[ind]}")
  203.             if ind in used and ind != 0:
  204.                 print("!!!программа ЗАЦИКЛИЛАСЬ!!!")
  205.                 cycle = True
  206.                 stop2 = time.perf_counter()
  207.                 print(f"\nВремя работы: {stop2 - start2} секунд")
  208.             elif ind == 0:
  209.                 print("!!!программа ЗАВЕРШИЛАСЬ!!!")
  210.                 cycle = True
  211.                 stop2 = time.perf_counter()
  212.                 print(f"\nВремя работы: {stop2 - start2} секунд")
  213.             else:
  214.                 used.append(ind)
  215.     else:
  216.         print("Неверный выбор режима работы")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement