Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created December 14, 2016 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisswarren/861f44527a73a312e77e2a79484d2eb3 to your computer and use it in GitHub Desktop.
Save louisswarren/861f44527a73a312e77e2a79484d2eb3 to your computer and use it in GitHub Desktop.
def twentyone(nums, stack=[]):
for index, num in enumerate(nums):
new_stack = stack + [num]
total = sum(new_stack)
if total == 21:
yield new_stack
elif total < 21:
yield from twentyone(nums[index+1:], new_stack)
print(list(twentyone([1,9,11,5,6])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment