Korotkodul

ИТМО N3

Apr 14th, 2022 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. def to(x, bs):
  2. r=[]
  3. st=x
  4. #print("GO")
  5. while x > 0:
  6. r.append(x%bs)
  7. x//=bs
  8. r=r[::-1]
  9. while len(r) < 4:
  10. #print("l=",len(r))
  11. #r = [*z, *r]
  12. #r = r[::-1]
  13. #r.append(0)
  14. #r = r[::-1]
  15. r = [0] + r
  16. print(st,r)
  17. return r
  18.  
  19. def f(x):
  20. print(x[0] or x[1] and x[2],x[1] or x[2] and x[3],x[2] or x[3] or x[0])
  21. print((x[0] or x[1] and x[2]) and (x[1] or x[2] and x[3] ) and (x[2] or x[3] or x[0]))
  22. return (x[0] or (x[1] and x[2])) and (x[1] or (x[2] and x[3] )) and (x[2] or x[3] or x[0])
  23.  
  24.  
  25.  
  26. num = []
  27. for i in range(16):
  28. num.append(i)
  29. num=num[::-1]
  30. Bnum = []
  31. print(num)
  32. #print(len(num))
  33. for i in range(16):
  34. Bnum.append(f(to(num[i],2)))
  35. print(Bnum)
  36.  
  37. zer=0
  38. one=0
  39. for i in range(16):
  40. if f(to(i,2)) == True:
  41. one+=1
  42. else:
  43. zer += 1
  44. print("zer one")
  45. print(zer, one)
  46.  
  47. Bzer = Bnum.count(0)
  48. Bone = Bnum.count(1)
  49. print(Bzer, Bone)
  50. res = zer ** Bzer * one ** Bone
  51. res = str(res)
  52. ans=0
  53. for i in res:
  54. ans += int(i)
  55. print(res)
  56. print("ans=",ans)
  57.  
Add Comment
Please, Sign In to add comment