aboutsummaryrefslogtreecommitdiff
path: root/challenge-082/walt-mankowski/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-082/walt-mankowski/python')
-rw-r--r--challenge-082/walt-mankowski/python/ch-1.py13
-rw-r--r--challenge-082/walt-mankowski/python/ch-2.py23
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-082/walt-mankowski/python/ch-1.py b/challenge-082/walt-mankowski/python/ch-1.py
new file mode 100644
index 0000000000..d0f56b7fcb
--- /dev/null
+++ b/challenge-082/walt-mankowski/python/ch-1.py
@@ -0,0 +1,13 @@
+from sys import argv
+from math import sqrt
+
+def factors(n):
+ s = set([1])
+ for i in range(2, int(sqrt(n))+1) :
+ if n % i == 0:
+ s.add(i)
+ s.add(n // i)
+ return s
+
+m, n = [int(x) for x in argv[1:]]
+print(factors(m) & factors(n))
diff --git a/challenge-082/walt-mankowski/python/ch-2.py b/challenge-082/walt-mankowski/python/ch-2.py
new file mode 100644
index 0000000000..ca2a2d551d
--- /dev/null
+++ b/challenge-082/walt-mankowski/python/ch-2.py
@@ -0,0 +1,23 @@
+from sys import argv
+
+def is_interleave(a, b, c):
+ if a == '' and b == '' and c == '':
+ return 1
+
+ try:
+ if a[0] == c[0]:
+ return is_interleave(a[1:], b, c[1:])
+ except IndexError:
+ pass
+
+ try:
+ if b[0] == c[0]:
+ return is_interleave(a, b[1:], c[1:])
+ except IndexError:
+ pass
+
+ return 0
+
+a, b, c = argv[1:]
+
+print(is_interleave(a, b, c))