Skip to content

Instantly share code, notes, and snippets.

@dilanshah
Last active March 2, 2018 19:11
Show Gist options
  • Save dilanshah/6695db9aa49375fbe4ced69ccf3acceb to your computer and use it in GitHub Desktop.
Save dilanshah/6695db9aa49375fbe4ced69ccf3acceb to your computer and use it in GitHub Desktop.
write a function to tell if a full deck of cards is a single riffle of two other halves, half1 and half2
# write a function to tell if a full deck of cards is a single riffle of two other halves, half1 and half2
import random
from collections import deque
h1 = deque(random.sample(range(1, 27), 26))
h2 = deque(random.sample(range(27, 53), 26))
print(h1)
print(h2)
shuffled_deck = deque(random.sample(range(1, 53), 52))
def riffle(half1, half2):
"""
:param half1: deque
:param half2: deque
:return: return bool
"""
print(shuffled_deck)
print(half1)
if len(shuffled_deck) == 0:
return True
else:
stored_value = shuffled_deck.popleft()
# check which half was used first
if stored_value == half1[0]:
half1.popleft()
return riffle(half1, half2)
elif stored_value == half2[0]:
half2.popleft()
return riffle(half1, half2)
else:
return False
print(riffle(h1, h2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment