import random
import time
class MagicCard(object):
def __init__(self,*card):
#1. tear the cards
self.cards = [*card]*2
def prove(self):
#2. insert the top to the bottom
n = random.randint(2,7)
self.cards = self.cards[n:]+self.cards[:n]
#3. insert the top to the middle
top_three,self.cards =self.cards[:3],self.cards[3:]
for card in top_three:
pos = random.randint(1,len(self.cards)-2)
self.cards.insert(pos,card)
#4. pop the stack
temp = self.cards.pop(0)
# 5. northern or southern people
num = random.randint(1,3)
tops,self.cards = self.cards[:num],self.cards[num:]
for card in tops:
pos = random.randint(1,len(self.cards)-2)
self.cards.insert(pos,card)
#6. sex
sex_num = random.randint(1,2)
self.cards[sex_num:]
#7. move the cards to the bottom of stack constantly
for _ in range(len(self.cards)):
self.cards.append(self.cards.pop(0))
#8. keep luck and throw annoyment
while(len(self.cards)>1):
self.cards.append(self.cards.pop(0)) # keep luck
self.cards.pop(0) # throw annoyment
return temp, self.cards[0]
positive_num = 0
iters = 1000
for _ in range(iters):
cle = MagicCard('A', 'B', 'C','D')
temp,last = cle.prove()
print(temp,'-->',last)
time.sleep(0.01)
if temp is last:
positive_num += 1
odds = positive_num / iters
print('the odds to meet you is {}%'.format((int(odds*100))))
if odds==1:
time.sleep(2)
print('we are destined to meet each other')
刘谦魔术栈模拟
最新推荐文章于 2024-07-12 16:16:27 发布