Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- AX = [False, False, False, False, False, False, False]
- Yarr = [False, False, False, False, False, False, False, False, False, False]
- STATES = ['SO', 'S1', 'S2', 'S3', 'S4', 'S5']
- used = []
- cycle = False
- # множества единичных наборов
- y1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
- y2 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
- y3 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
- y4 = [40, 41, 42, 43, 44, 45, 46, 47]
- y5 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
- y6 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
- y7 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
- y8 = [70, 71, 78, 79]
- y9 = [81, 83, 85, 87, 89, 91, 93, 95]
- y10 = [68, 69, 76, 77]
- w1 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
- 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]
- 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,
- 38, 39, 70, 71, 78, 79]
- 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,
- 94]
- u2 = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
- 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,
- 86, 88, 90, 92, 94, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
- def set_null():
- Yarr = [False, False, False, False, False, False, False, False, False, False]
- # определение индекса текущего состояния
- def get_state():
- index = 0
- if AX[0]:
- index += 4
- if AX[1]:
- index += 2
- if AX[2]:
- index += 1
- return index
- def setSYbyLogic():
- Yarr[0] = not AX[0] and not AX[1] and not AX[2]
- Yarr[1] = Yarr[2] = not AX[0] and not AX[1] and AX[2]
- Yarr[3] = not AX[0] and AX[1] and not AX[2] and AX[3]
- Yarr[4] = Yarr[5] = Yarr[6] = not AX[0] and AX[1] and AX[2]
- Yarr[7] = AX[0] and not AX[1] and not AX[2] and AX[4] and AX[5]
- Yarr[8] = AX[0] and not AX[1] and AX[2] and AX[6]
- Yarr[9] = AX[0] and not AX[1] and not AX[2] and AX[4] and not AX[5]
- W = [False, False, False]
- U = [False, False, False]
- W[0] = not AX[0] and AX[1] and AX[2]
- W[1] = not AX[0] and not AX[1] and AX[2] or \
- AX[0] and not AX[1] and not AX[2] and not AX[4]
- W[2] = not AX[0] and not AX[1] and not AX[2] or \
- not AX[0] and AX[1] and not AX[2] and AX[3] or \
- not AX[0] and AX[1] and not AX[2] and not AX[3] or \
- AX[0] and not AX[1] and not AX[2] and AX[4] and AX[5]
- U[0] = AX[0] and not AX[1] and not AX[2] and not AX[4] or \
- AX[0] and AX[1] and AX[2] and AX[4] and not AX[5] or \
- AX[0] and not AX[1] and AX[2] and not AX[6] or \
- AX[0] and not AX[1] and AX[2] and AX[6] or \
- AX[0] and not AX[1] and not AX[2] and AX[4] and not AX[5]
- U[1] = not AX[0] and AX[1] and AX[2]
- U[2] = not AX[0] and not AX[1] and AX[2] or \
- not AX[0] and AX[1] and AX[2] or \
- AX[0] and not AX[1] and AX[2] and not AX[6] or \
- AX[0] and not AX[1] and AX[2] and AX[6] or \
- AX[0] and AX[1] and AX[2] and AX[4] and not AX[5]
- for i in range(3):
- if W[i]:
- AX[i] = True
- if U[i]:
- AX[i] = False
- def setSYbyBinSets(num):
- if num in y1:
- Yarr[0] = True
- else:
- Yarr[0] = False
- if num in y2:
- Yarr[1] = True
- else:
- Yarr[1] = False
- if num in y3:
- Yarr[2] = True
- else:
- Yarr[2] = False
- if num in y4:
- Yarr[3] = True
- else:
- Yarr[3] = False
- if num in y5:
- Yarr[4] = True
- else:
- Yarr[4] = False
- if num in y6:
- Yarr[5] = True
- else:
- Yarr[5] = False
- if num in y7:
- Yarr[6] = True
- else:
- Yarr[6] = False
- if num in y8:
- Yarr[7] = True
- else:
- Yarr[7] = False
- if num in y9:
- Yarr[8] = True
- else:
- Yarr[8] = False
- if num in y10:
- Yarr[9] = True
- else:
- Yarr[9] = False
- if num in w1:
- AX[0] = True
- if num in u1:
- AX[0] = False
- if num in w2:
- AX[1] = True
- if num in u2:
- AX[1] = False
- if num in w3:
- AX[2] = True
- if num in u3:
- AX[2] = False
- if __name__ == "__main__":
- for i in range(4):
- ch = input(f"Введите x{i + 1}: ")
- if ch == '1':
- AX[i + 3] = True
- else:
- AX[i + 3] = False
- method = input("введите режим работы:\n1 - логические выражения;\n2 - множество единичных наборов;\n")
- if method == '1':
- print("S(НАЧ) -> Yarr (y1-y10) -> S(КОН)")
- start = time.perf_counter()
- used.append(0)
- while not cycle:
- ind = get_state()
- print(STATES[ind], end=" -> ")
- setSYbyLogic()
- for y in Yarr:
- if y:
- print('1', end="")
- else:
- print('0', end="")
- ind = get_state()
- print(f" -> {STATES[ind]}")
- if ind in used and ind != 0:
- print("!!!программа ЗАЦИКЛИЛАСЬ!!!")
- cycle = True
- stop = time.perf_counter()
- print(f"\nВремя работы: {stop - start} секунд")
- elif ind == 0:
- print("!!!программа ЗАВЕРШИЛАСЬ!!!")
- stop = time.perf_counter()
- print(f"\nВремя работы: {stop - start} секунд")
- cycle = True
- else:
- used.append(ind)
- set_null()
- elif method == '2':
- print("S(НАЧ) -> Yarr (y1-y10) -> S(КОН)")
- start2 = time.perf_counter()
- used.append(0)
- while not cycle:
- ind = get_state()
- print(STATES[ind], end=" -> ")
- mpow = 6
- num = 0
- for i in AX:
- if i:
- num += 2 ** mpow
- mpow -= 1
- setSYbyBinSets(num)
- for y in Yarr:
- if y:
- print('1', end="")
- else:
- print('0', end="")
- ind = get_state()
- print(f" -> {STATES[ind]}")
- if ind in used and ind != 0:
- print("!!!программа ЗАЦИКЛИЛАСЬ!!!")
- cycle = True
- stop2 = time.perf_counter()
- print(f"\nВремя работы: {stop2 - start2} секунд")
- elif ind == 0:
- print("!!!программа ЗАВЕРШИЛАСЬ!!!")
- cycle = True
- stop2 = time.perf_counter()
- print(f"\nВремя работы: {stop2 - start2} секунд")
- else:
- used.append(ind)
- else:
- print("Неверный выбор режима работы")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement