aboutsummaryrefslogtreecommitdiff
path: root/challenge-141/abigail/python/ch-2.py
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-30 20:04:35 +0100
committerAbigail <abigail@abigail.be>2021-11-30 20:04:35 +0100
commit44bcd3ae0c35b887bd579e60c17198360f3497c3 (patch)
tree1fce654d4b0b27996ef85e24d2bafabf7541ffc7 /challenge-141/abigail/python/ch-2.py
parenta53828c517ea7368d0efc3f64779bd0853c17330 (diff)
downloadperlweeklychallenge-club-44bcd3ae0c35b887bd579e60c17198360f3497c3.tar.gz
perlweeklychallenge-club-44bcd3ae0c35b887bd579e60c17198360f3497c3.tar.bz2
perlweeklychallenge-club-44bcd3ae0c35b887bd579e60c17198360f3497c3.zip
Solutions week 141
Diffstat (limited to 'challenge-141/abigail/python/ch-2.py')
-rw-r--r--challenge-141/abigail/python/ch-2.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-141/abigail/python/ch-2.py b/challenge-141/abigail/python/ch-2.py
new file mode 100644
index 0000000000..61cc8cdd25
--- /dev/null
+++ b/challenge-141/abigail/python/ch-2.py
@@ -0,0 +1,32 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+import fileinput
+
+def substrings (n, m, prefix, max):
+ if len (n) == 0:
+ if prefix > -1 and prefix < max and prefix % m == 0:
+ return 1
+ else:
+ return 0
+
+ fc = int (n [0 : 1])
+ tail = n [1:]
+ if prefix == -1:
+ n_prefix = fc
+ else:
+ n_prefix = 10 * prefix + fc
+
+ return substrings (tail, m, n_prefix, max) + \
+ substrings (tail, m, prefix, max)
+
+for line in fileinput . input ():
+ n, m = line . strip () . split (" ")
+ print (substrings (n, int (m), -1, int (n)))