Skip to content

Instantly share code, notes, and snippets.

@RobertTalbert
Created October 20, 2021 16:16
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 RobertTalbert/a483a536ae2d2e9e653e03fe54e9aba5 to your computer and use it in GitHub Desktop.
Save RobertTalbert/a483a536ae2d2e9e653e03fe54e9aba5 to your computer and use it in GitHub Desktop.
# To find the natural number solutions to x + y + z = 8
[(x,y,z) for x in range(9) for y in range(9) for z in range(9) if x+y+z == 8]
# To generate the ways to pick 6 donuts from an unlimited supply of glazed, chocolate, and jelly-filled
[(g,c,j) for g in range(7) for c in range(7) for j in range(7) if g+c+j == 6]
# Put `len( )` around these lists to find the number of items in the list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment