Guest User

Парадокс Монти Холла

a guest
Nov 21st, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import numpy as np
  2. # generate random integer values
  3. from random import seed
  4. from random import randint
  5. # seed random number generator
  6. seed(1344)
  7. x = np.zeros((1000,3,3)) # Make a 10 by 20 by 30 array
  8. for i in range(1000):
  9.     r = randint(0,2)
  10.     x[i,r,0] = 1
  11. for i in range(1000):
  12.     r = randint(0,2)
  13.     x[i,r,1] = 1    
  14.  
  15. for i in range(1000):
  16.     if x[i,0,0] == 1 and x[i,0,1] == 1:
  17.         rr = randint(0,1) + 1
  18.         x[i,rr,2] = 1
  19.     if x[i,0,0] == 1 and x[i,1,1] == 1:
  20.         x[i,2,2] = 1
  21.     if x[i,0,0] == 1 and x[i,2,1] == 1:
  22.         x[i,1,2] = 1
  23.    
  24.     if x[i,1,0] == 1 and x[i,0,1] == 1:
  25.         x[i,2,2] = 1
  26.     if x[i,1,0] == 1 and x[i,1,1] == 1:
  27.         rr = randint(0,1)*2
  28.         x[i,rr,2] = 1
  29.     if x[i,1,0] == 1 and x[i,2,1] == 1:
  30.         x[i,0,2] = 1
  31.    
  32.     if x[i,2,0] == 1 and x[i,0,1] == 1:
  33.         x[i,1,2] = 1
  34.     if x[i,2,0] == 1 and x[i,1,1] == 1:
  35.         x[i,0,2] = 1
  36.     if x[i,2,0] == 1 and x[i,2,1] == 1:
  37.         rr = randint(0,1)
  38.         x[i,rr,2] = 1
  39.  
  40. winbystay = 0
  41. winbychange = 0
  42.  
  43. for i in range(1000):
  44.     for ii in range(3):
  45.         if x[i,ii,0] == 1 and x[i,ii,1] == 1:
  46.             winbystay = winbystay + 1
  47.         if x[i,ii,0] == 1 and x[i,ii,1] == 0 and x[i,ii,2] == 0:
  48.             winbychange = winbychange + 1
  49. print(winbystay)
  50. print(winbychange)
  51.            
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment