aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/stuart-little/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-113/stuart-little/python/ch-1.py')
-rwxr-xr-xchallenge-113/stuart-little/python/ch-1.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-113/stuart-little/python/ch-1.py b/challenge-113/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..bbaaf80337
--- /dev/null
+++ b/challenge-113/stuart-little/python/ch-1.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+# run <script> <number> <digit>
+
+import sys
+
+def lastDigSumm(nr, dig, nrSummands):
+ return ((nr - nrSummands * dig) % 10 == 0) and (nrSummands * dig <= nr) and (nrSummands * ((dig -1) * 10 + dig) >= nr)
+
+def lastDig(nr,dig):
+ return bool(list(filter(lambda x: lastDigSumm(nr,dig,x), range(1,10))))
+
+def sol(nr,dig):
+ if (dig == 0):
+ return (nr >= 101 or (nr % 10 == 0))
+ return ((nr >= dig * 11) or lastDig(nr,dig));
+
+print(int(sol(*map(int,sys.argv[1:]))))