aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-10-25 19:08:56 +0200
committerAbigail <abigail@abigail.be>2021-10-25 19:08:56 +0200
commitf8a11d05ad884a0d97b17c5f21c40cdd6cf11659 (patch)
treef901860256b69efe203ad90acc452233ac6975d8
parent1ef7e3e41c765b9c0d1c4fef3683d685494dbc29 (diff)
downloadperlweeklychallenge-club-f8a11d05ad884a0d97b17c5f21c40cdd6cf11659.tar.gz
perlweeklychallenge-club-f8a11d05ad884a0d97b17c5f21c40cdd6cf11659.tar.bz2
perlweeklychallenge-club-f8a11d05ad884a0d97b17c5f21c40cdd6cf11659.zip
Python solutions for week 136
-rw-r--r--challenge-136/abigail/README.md2
-rw-r--r--challenge-136/abigail/python/ch-1.py23
-rw-r--r--challenge-136/abigail/python/ch-2.py22
3 files changed, 47 insertions, 0 deletions
diff --git a/challenge-136/abigail/README.md b/challenge-136/abigail/README.md
index 06e1bd7918..b655b703ea 100644
--- a/challenge-136/abigail/README.md
+++ b/challenge-136/abigail/README.md
@@ -8,6 +8,7 @@
* [Lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
* [Perl](perl/ch-1.pl)
+* [Python](python/ch-1.py)
## Part 2
@@ -16,3 +17,4 @@
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
* [Perl](perl/ch-2.pl)
+* [Python](python/ch-2.py)
diff --git a/challenge-136/abigail/python/ch-1.py b/challenge-136/abigail/python/ch-1.py
new file mode 100644
index 0000000000..86da426994
--- /dev/null
+++ b/challenge-136/abigail/python/ch-1.py
@@ -0,0 +1,23 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+import math
+
+for line in fileinput . input ():
+ m, n = line . strip () . split (' ')
+ gcd = math . gcd (int (m), int (n))
+ valid = 0
+ if gcd > 1:
+ while gcd % 2 == 0:
+ gcd = gcd / 2
+ if gcd == 1:
+ valid = 1
+ print (valid)
diff --git a/challenge-136/abigail/python/ch-2.py b/challenge-136/abigail/python/ch-2.py
new file mode 100644
index 0000000000..8a73a45846
--- /dev/null
+++ b/challenge-136/abigail/python/ch-2.py
@@ -0,0 +1,22 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+def count (target, this_fib, prev_fib):
+ if target < this_fib:
+ return (0)
+ if target == this_fib:
+ return (1)
+ return (count (target - this_fib, this_fib + prev_fib, this_fib) +
+ count (target, this_fib + prev_fib, this_fib))
+
+import fileinput
+
+for line in fileinput . input ():
+ print (count (int (line), 1, 1))