Created
October 28, 2016 18:05
-
-
Save jaymcgrath/ede53be86129524b9d216fc795993ea7 to your computer and use it in GitHub Desktop.
Solving Chinese Puzzle of Rabbits and Chickens with a list comprehension in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a farm with rabbits and chickens, you count 35 heads and 94 legs. How many of each animal do you have? | |
Assume all rabbits and chickens have 4 and 2 legs respectively. | |
""" | |
from itertools import combinations_with_replacement | |
print([x for x in combinations_with_replacement([2,4],35) if sum(x) == 94]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment