Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import time
- SIZE = 4
- A_SIZE = 4
- Y_SIZE = 11
- S_SIZE = 3
- R_SIZE = 3
- '''
- def mnoj(arr, res):
- if res in arr:
- return True
- return False
- '''
- def mnoj(arr, len, res):
- for i in range(len):
- if arr[i] == res:
- return True
- return False
- def toDec(a):
- num = 0
- for i in range(SIZE - 1, -1, -1):
- num += int(math.pow(2, (SIZE - 1) - i)) * a[i]
- return num
- def updateY(a, x, y):
- y[0] = not a[0] and not a[1] and not a[2]
- y[1] = not a[0] and not a[1] and a[2]
- y[2] = not a[0] and not a[1] and a[2]
- y[3] = not a[0] and a[1] and not a[2] and x[0]
- y[4] = not a[0] and a[1] and a[2]
- y[5] = not a[0] and a[1] and a[2]
- y[6] = not a[0] and a[1] and a[2]
- y[7] = a[0] and not a[1] and not a[2] and x[1] and x[2]
- y[8] = a[0] and not a[1] and a[2] and x[3]
- y[9] = a[0] and not a[1] and not a[2] and x[1] and not x[2]
- def updateS(a, s, x):
- s[0] = not a[0] and a[1] and a[2]
- s[1] = (not a[0] and not a[1] and a[2]) or (a[0] and not a[1] and not a[2] and not x[0])
- s[2] = (not a[0] and not a[1] and not a[2]) or (not a[0] and a[1] and not a[2] and not x[1]) or (not a[0] and a[1] and not a[2] and x[1]) or (a[0] and not a[1] and not a[2] and x[0] and x[1] and not x[2])
- # u1 u2 u3 в отчете (функции возбуждения)
- def updateR(a, x, r):
- r[0] = (a[0] * (not a[1]) * (not a[2]) * x[0] * (not x[1])) + (a[0] * (not a[1]) * (not a[2]) * (not x[0])) + (a[0] * (not a[1]) * a[2] * x[2]) + (a[0] * (not a[1]) * a[2] * (not x[2]))
- r[1] = (not a[0]) * a[1] * a[2]
- r[2] = ((not a[0]) * (not a[1]) * a[2]) + ((not a[0]) * a[1] * a[2]) + (a[0] * (not a[1]) * a[2] * x[2]) + (a[0] * (not a[1]) * a[2] * (not x[2]))
- def changeA(a, s, r):
- for i in range(1, A_SIZE):
- if s[i]:
- a[i] = True
- if r[i]:
- a[i] = False
- def printVector(v):
- for i in range(1, Y_SIZE):
- print(v[i], end=" ")
- # print()
- def printVectorA(v):
- for i in range(1, A_SIZE):
- print(v[i], end=" ")
- # print()
- def addState(S, a, y):
- print("Состояние: S{}".format(S))
- print("Вывод состояний a: ", end="")
- printVectorA(a)
- print("\nВывод состояний y: ", end="")
- printVector(y)
- print()
- check = int(input("1. Логические выражения. 2. Множество единичных наборов. "))
- if check == 1:
- x = [False] * SIZE
- for i in range(SIZE):
- x[i] = bool(input("Введите x: ").split())
- start = time.perf_counter()
- a = [False] * (A_SIZE + 1)
- y = [False] * (Y_SIZE + 1)
- s = [False] * (S_SIZE + 1)
- r = [False] * (R_SIZE + 1)
- checkFirst = [False] * int(math.pow(2, SIZE))
- checkSecond = [False] * int(math.pow(2, SIZE))
- # checkFirst = [False] * (1 << SIZE)
- # checkSecond = [False] * (1 << SIZE)
- S = 0
- while not checkSecond[S]:
- S = toDec(a)
- if checkFirst[S]:
- checkSecond[S] = True
- else:
- checkFirst[S] = True
- if checkSecond[S]:
- break
- addState(S, a, y)
- updateY(a, x, y)
- updateR(a, x, r)
- updateS(a, s, x)
- changeA(a, s, r)
- if S == 0:
- addState(S, a, y)
- stop = time.perf_counter()
- print(f"\nВремя работы: {stop - start:0.4f} секунд")
- print("Конец")
- else:
- addState(S, a, y)
- stop = time.perf_counter()
- print(f"\nВремя работы: {stop - start:0.4f} секунд")
- print("Цикл")
- else:
- 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]
- X = [0]*4
- Y = [0]*10
- S = [0, 0, 0]
- for i in range(4):
- X[i] = bool(input("Введите x: ").split())
- CS = [0] * 7
- res = 0
- start2 = time.perf_counter()
- for i in range(3):
- CS[i] = S[i]
- for i in range(4):
- CS[i + 3] = X[i]
- res = 0
- for i in range(8):
- for j in range(6, -1, -1):
- res += pow(2, j) * CS[6 - j]
- print("\nS(", end="")
- for j in range(3):
- print(S[j], end="")
- if mnoj(y1, 16, res):
- Y[0] = 1
- else:
- Y[0] = 0
- if mnoj(y2, 16, res):
- Y[1] = 1
- else:
- Y[1] = 0
- if mnoj(y3, 16, res):
- Y[2] = 1
- else:
- Y[2] = 0
- if mnoj(y4, 8, res):
- Y[3] = 1
- else:
- Y[3] = 0
- if mnoj(y5, 16, res):
- Y[4] = 1
- else:
- Y[4] = 0
- if mnoj(y6, 16, res):
- Y[5] = 1
- else:
- Y[5] = 0
- if mnoj(y7, 16, res):
- Y[6] = 1
- else:
- Y[6] = 0
- if mnoj(y8, 4, res):
- Y[7] = 1
- else:
- Y[7] = 0
- if mnoj(y9, 8, res):
- Y[8] = 1
- else:
- Y[8] = 0
- if mnoj(y10, 4, res):
- Y[9] = 1
- else:
- Y[9] = 0
- if mnoj(w1, 16, res):
- S[0] = 1
- if mnoj(w2, 24, res):
- S[1] = 1
- if mnoj(w3, 36, res):
- S[2] = 1
- if mnoj(u1, 28, res):
- S[0] = 0
- if mnoj(u2, 16, res):
- S[1] = 0
- if mnoj(u3, 48, res):
- S[2] = 0
- print(") -> S(", end="")
- for j in range(3):
- print(S[j], end="")
- print(") Y(1-10):", end="")
- for j in range(10):
- print(" ", Y[j], end="")
- for j in range(3):
- CS[j] = S[j]
- if S[0] + S[1] + S[2] == 0:
- print("\nПрограмма завершена")
- break
- stop2 = time.perf_counter()
- print(f"\nВремя работы: {stop2 - start2:0.4f} секунд")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement