aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/abigail/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-23 16:59:39 +0100
committerGitHub <noreply@github.com>2021-05-23 16:59:39 +0100
commit64d90deae0b1c6e8fe708937f775f0975f138a4f (patch)
treecf2877cafb333f34246a86a5ab81a0abd8d07899 /challenge-113/abigail/python/ch-1.py
parentd03259c86c349e8efbbd6622dfdfcaa3c5f527f2 (diff)
parent1ab38e5de2d0bbab588c411e7764653217a9fc84 (diff)
downloadperlweeklychallenge-club-64d90deae0b1c6e8fe708937f775f0975f138a4f.tar.gz
perlweeklychallenge-club-64d90deae0b1c6e8fe708937f775f0975f138a4f.tar.bz2
perlweeklychallenge-club-64d90deae0b1c6e8fe708937f775f0975f138a4f.zip
Merge pull request #4120 from Abigail/abigail/week-113
Abigail/week 113
Diffstat (limited to 'challenge-113/abigail/python/ch-1.py')
-rw-r--r--challenge-113/abigail/python/ch-1.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-113/abigail/python/ch-1.py b/challenge-113/abigail/python/ch-1.py
new file mode 100644
index 0000000000..ebb8821ddc
--- /dev/null
+++ b/challenge-113/abigail/python/ch-1.py
@@ -0,0 +1,40 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+#
+# For a description of the algorithm, and the proof why this is correct:
+# https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-113-1.html
+#
+
+import fileinput
+
+gcds = [0, 1, 2, 1, 2, 5, 2, 1, 2, 1]
+
+for line in fileinput . input ():
+ (N, D) = line . split ();
+ N = int (N)
+ D = int (D)
+ if D == 0:
+ print (1 if N >= 100 or N % 10 == 0 else 0)
+ continue
+
+ if N >= D * 10:
+ print (1)
+ continue
+
+ done = False
+ for i in range (0, D // gcds [D]):
+ T = N - 10 * i - D
+ if T >= 0 and T % D == 0:
+ print (1)
+ done = True
+ break
+ if not done:
+ print (0)