From cf8a21bfd37f157e2ec075799c2c548628623102 Mon Sep 17 00:00:00 2001
From: Anurag Kumar
Date: Thu, 26 Oct 2017 13:41:03 +0530
Subject: [PATCH] added Chickens and Rabbits(Ancient Chinese Puzzle) Question.
---
chicks_n_rabs.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 chicks_n_rabs.py
diff --git a/chicks_n_rabs.py b/chicks_n_rabs.py
new file mode 100644
index 00000000000..1b4dabb9cce
--- /dev/null
+++ b/chicks_n_rabs.py
@@ -0,0 +1,22 @@
+'''Author Anurag Kumar(mailto:[email protected])
+
+Module to solve a classic ancient Chinese puzzle:
+We count 35 heads and 94 legs among the chickens and rabbits in a farm.
+How many rabbits and how many chickens do we have?
+
+
+'''
+def solve(numheads,numlegs):
+ ns='No solutions!'
+ for i in range(numheads+1):
+ j=numheads-i
+ if 2*i+4*j==numlegs:
+ return i,j
+ return ns,ns
+
+if __name__=="__main__":
+ numheads=35
+ numlegs=94
+
+ solutions=solve(numheads,numlegs)
+ print(solutions)