Skip to content

Instantly share code, notes, and snippets.

@acbart
Created November 11, 2018 02:45
Show Gist options
  • Select an option

  • Save acbart/aa23485b0074e25cd8fa4c120a5451d7 to your computer and use it in GitHub Desktop.

Select an option

Save acbart/aa23485b0074e25cd8fa4c120a5451d7 to your computer and use it in GitHub Desktop.
SUITS = ['♠', '♦', '♥', '♣']
RANKS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
ALL = [rank+suit for rank in RANKS for suit in SUITS]
def backtrack(a, k):
if is_solution(a):
process_solution(a)
else:
k = k + 1
candidates = construct_candidates(a, k)
for candidate in candidates:
a.append(candidate)
backtrack(a, k)
a.pop() # Backtracking
def permute_cards(hand, deck, max_hand=5):
if len(hand) == max_hand:
print(hand)
else:
candidates = [card for card in deck if card not in hand]
for candidate in candidates:
hand.append(candidate)
permute_cards(hand, deck, max_hand)
hand.pop()
permute_cards([], ALL, max_hand=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment