Skip to content

Commit cf8a21b

Browse files
added Chickens and Rabbits(Ancient Chinese Puzzle) Question.
1 parent 8113b9a commit cf8a21b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

chicks_n_rabs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''Author Anurag Kumar(mailto:anuragkumarak95@gmail.com)
2+
3+
Module to solve a classic ancient Chinese puzzle:
4+
We count 35 heads and 94 legs among the chickens and rabbits in a farm.
5+
How many rabbits and how many chickens do we have?
6+
7+
8+
'''
9+
def solve(numheads,numlegs):
10+
ns='No solutions!'
11+
for i in range(numheads+1):
12+
j=numheads-i
13+
if 2*i+4*j==numlegs:
14+
return i,j
15+
return ns,ns
16+
17+
if __name__=="__main__":
18+
numheads=35
19+
numlegs=94
20+
21+
solutions=solve(numheads,numlegs)
22+
print(solutions)

0 commit comments

Comments
 (0)