Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import shuffle
- # Function 0 - Create a cards deck
- def createCards():
- cards = list()
- for i in range(1, 14):
- for j in range(4):
- cards.append(i)
- return cards
- # Function 1 - Decide how many times I will shuffle the deck
- def SHUFFLE(cards, n):
- for i in range(n):
- shuffle(cards)
- return cards
- # Function 2 - Decide if there are any consecutive cards
- def consecutive(cards):
- flag = True
- index = -1000
- for i in range(len(cards) - 1):
- if cards[i] == cards[i+1]:
- flag = False
- index = i
- break
- return flag, index
- # Function 3 - Simulate rounds with a given n = how many shuffles
- def simulate(LIMIT, n):
- good = 0
- for round in range(1, LIMIT+1):
- cards = createCards()
- cards = SHUFFLE(cards, n)
- flag, index = consecutive(cards)
- if flag == True:
- good += 1
- return good
- # MAIN FUNCTION
- LIMIT = 10**4
- nList = list(range(1, 5))
- for n in nList:
- good = simulate(LIMIT, n)
- percentage100 = 100 * good / LIMIT
- print(str(n) + " shuffles ---> " + str(good) + " successes ---> " + str(percentage100) + "%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement