Advertisement
boris-vlasenko

ege 23 проверка одного из наборов

Oct 27th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. #a = '-((-(x & 56 <> 0) v (x & 18 <> 0)) v (x & A <> 0)) v ((x & 18 = 0) ^ (x & A = 0) ^ (x & 43 <> 0)) '
  2. a = '((x1 ∨ x2) ∧ (-(x1 ∧ x2) v y1)) and ((x2 ∨ x3) ∧ (-(x2 ∧ x3) v y2)) and ((x3 ∨ x4) ∧ (-(x3 ∧ x4) v y3)) and ((x4 ∨ x5) ∧ (-(x4 ∧ x5) v y4)) and ((x5 ∨ x6) ∧ (x5 ∨ y5)) and (x6 ∨ y6)'
  3. a = '''
  4. ((x1 ∨ x2) ∧ (-(x1 ∧ x2) or x3) ∧ (x1 ∨ y1)) and \
  5. ((x2 ∨ x3) ∧ (-(x2 ∧ x3) or x4) ∧ (x2 ∨ y2)) and \
  6. ((x3 ∨ x4) ∧ (-(x3 ∧ x4) or x5) ∧ (x3 ∨ y3)) and \
  7. ((x4 ∨ x5) ∧ (-(x4 ∧ x5) or x6) ∧ (x4 ∨ y4)) and \
  8. ((x5 ∨ x6) ∧ (-(x5 ∧ x6) or x7) ∧ (x5 ∨ y5)) and \
  9. ((x6 ∨ x7) ∧ (-(x6 ∧ x7) or x8) ∧ (x6 ∨ y6)) and \
  10. ((x7 ∨ x8) ∧ (x7 ∨ y7)) and \
  11. (x8 ∨ y8) = 1
  12. '''
  13.  
  14. nx = 8
  15. ny = 8
  16.  
  17. a = a.replace('v',' or ')
  18. a = a.replace('∨',' or ')
  19. a = a.replace('^',' and ')
  20. a = a.replace('∧',' and ')
  21. a = a.replace('-',' not ')
  22. a = a.replace('¬',' not ')
  23. #a = a.replace('ДЕЛ',' test_del')
  24. a = a.replace('А','A')
  25. a = a.replace('X','x')
  26. a = a.replace('≠','!=')
  27. a = a.replace('<>','!=')
  28. a = a.replace(' = ',' == ')
  29.  
  30. a = ' '.join([x for x in a.split(' ') if x])
  31. print(a)
  32. print()
  33.  
  34. def tobin(a,n):
  35.     res = ''
  36.     while a:
  37.         res = str(a % 2) + res
  38.         a = a // 2
  39.     n = n - len(res)
  40.     if n > 0:
  41.         res = '0'*n + res
  42.     return list(map(int,res))
  43.  
  44.  
  45.  
  46. kx = 0
  47. k = 0  
  48. for x in range(2**nx):
  49.     xx = tobin(x,nx)
  50.     test_a = a
  51.     for ii in range(1,nx+1):
  52.         test_a = test_a.replace('x'+str(ii),str(xx[ii-1]))
  53.     for ii in range(1,ny+1):
  54.         test_a = test_a.replace('y'+str(ii),'1')
  55.        
  56.     if eval(test_a):
  57.         print(''.join(map(str,xx)), end= '  >> ')
  58.         kx += 1
  59.         ky = 0
  60.         for y in range(2**ny):
  61.             yy = tobin(y,ny)
  62.             test_a = a
  63.             for ii in range(1,nx+1):
  64.                 test_a = test_a.replace('x'+str(ii),str(xx[ii-1]))
  65.             for ii in range(1,ny+1):
  66.                 test_a = test_a.replace('y'+str(ii),str(yy[ii-1]))
  67.             if eval(test_a):
  68.                 ky += 1
  69.                 k += 1
  70.                 #print(*yy)
  71.         print(ky)
  72. print(kx,k)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement