Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. import random
  2. def n2(user):
  3.     stack=0
  4.     path=[]
  5.     slot=2
  6.     while user:
  7.             first=[]
  8.             for i in user:
  9.                 ran=i*random.randint(0,1)
  10.                 first+=[ran]
  11.                
  12.             if ((first[0]==user[0]) and (first[1]==user[1]))or((first[0]=='') and (first[1]=='')):
  13.                 slot+=2
  14.                 if((first[0]==user[0]) and (first[1]==user[1])) :
  15.                     path.append([str(user[0])+str(user[1]),''])
  16.                 else:
  17.                     path.append(['',str(user[0])+str(user[1])])
  18.                 continue
  19.            
  20.             if (first[0]== user[0]) and (first[1]== ''):
  21.                 path.append([user[0],user[1]])
  22.                 stack+=slot
  23.                 break
  24.             if (first[0]== '') and (first[1]== user[1]):
  25.                 path.append([user[1],user[0]])
  26.                 stack+=slot
  27.                 break
  28.     return([stack,path])
  29.  
  30. alluser=['A','B','C']
  31. av=0
  32. for k in range(1000):
  33.     p=[]
  34.     slot=0
  35.     while alluser:
  36.         first=[]
  37.         used=[]
  38.         last=[]
  39.         for i in alluser:
  40.             ran=i*random.randint(0,1)
  41.             first+=[ran]
  42.            
  43.         if (first==alluser)or(first==['','','']):
  44.             slot+=2
  45.             if(first==alluser):
  46.                 p.append([str(alluser[0])+str(alluser[1])+str(alluser[2]),''])
  47.             else:
  48.                 p.append(['',[str(alluser[0])+str(alluser[1])+str(alluser[2])]])
  49.             continue
  50.        
  51.         for j in range(len(first)):
  52.             if first[j]!='':
  53.                 used.append(first[j])#ถูกใช้ในfunction
  54.             else:
  55.                 last+=[alluser[j]]#ถูกใช้ในfunction
  56.  
  57.         if len(used)==1:
  58.             c=random.randint(0,1)
  59.             if c==0:
  60.                 p.append([used[0],last[0]+last[1]])
  61.             else:
  62.                 p.append([last[0]+last[1],used[0]])
  63.             slot+=2
  64.             stack,path= n2(last)
  65.             av+=slot+stack
  66.             print('slot =',slot+stack,',','path =',p+path)    
  67.             break
  68.        
  69.         if len(used)==2:
  70.             slot+=2#p.append([used[0]+used[1],''])
  71.             c=random.randint(0,1)
  72.             if c==0:
  73.                 p.append([used[0]+used[1],''])
  74.             else:
  75.                 p.append(['',used[0]+used[1]])
  76.             slot+=2  #[last[0],'']
  77.             stack,path= n2(used)
  78.             av+=slot+stack
  79.             d=random.randint(0,1)
  80.             if d==0:
  81.                 e=[[last[0],'']]
  82.             else:
  83.                 e=[['',last[0]]]
  84.             print('slot =',slot+stack,',','path =',p+path+e)
  85.             break
  86.  
  87. av/=1000  
  88. print('av_slot=',av)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement