aboutsummaryrefslogtreecommitdiff
path: root/challenge-141/abigail/python
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-12-06 14:55:30 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-12-06 14:55:30 +0000
commitcd04687f29d4ebea2fd5ec165585b21f2951f413 (patch)
tree5c17b623d6b7a8cb803a4464f19d157152143e62 /challenge-141/abigail/python
parentfe57a0405720a40beaeb75100e069aaa13e4c49e (diff)
parentb9773f5c38387d865a093d2ecdfd1b01b4452c34 (diff)
downloadperlweeklychallenge-club-cd04687f29d4ebea2fd5ec165585b21f2951f413.tar.gz
perlweeklychallenge-club-cd04687f29d4ebea2fd5ec165585b21f2951f413.tar.bz2
perlweeklychallenge-club-cd04687f29d4ebea2fd5ec165585b21f2951f413.zip
Merge branch 'master' into devel
Diffstat (limited to 'challenge-141/abigail/python')
-rw-r--r--challenge-141/abigail/python/ch-1.py30
-rw-r--r--challenge-141/abigail/python/ch-2.py32
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-141/abigail/python/ch-1.py b/challenge-141/abigail/python/ch-1.py
new file mode 100644
index 0000000000..cd4c0b5d3b
--- /dev/null
+++ b/challenge-141/abigail/python/ch-1.py
@@ -0,0 +1,30 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py
+#
+
+import math
+
+count = 10
+nr_of_divisors = 8
+
+n = 0
+while count > 0:
+ n = n + 1
+ s = math . floor (math . sqrt (n))
+ if n == s * s:
+ continue
+ c = 0
+ for d in range (1, s + 1):
+ if n % d == 0:
+ c = c + 2
+ if c > nr_of_divisors:
+ break
+ if c == nr_of_divisors:
+ print (n)
+ count = count - 1
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)))