aboutsummaryrefslogtreecommitdiff
path: root/challenge-005/zapwai/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-005/zapwai/python/ch-1.py')
-rw-r--r--challenge-005/zapwai/python/ch-1.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-005/zapwai/python/ch-1.py b/challenge-005/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..f9e2325e66
--- /dev/null
+++ b/challenge-005/zapwai/python/ch-1.py
@@ -0,0 +1,34 @@
+import sys
+def a(word):
+ A = []
+ if len(word) == 1:
+ A.append(word)
+ return A
+ letters = list(word)
+ for i in range(len(word)):
+ leftover = ""
+ for j in range(len(word)):
+ if i == j:
+ continue
+ else:
+ leftover += letters[j]
+ new_words = a(leftover)
+ for w in new_words:
+ new_word = letters[i] + w
+ A.append(new_word)
+ return A
+args = sys.argv[1:]
+for word in args:
+ words = set(a(word.lower()))
+ fn = "/usr/share/dict/words"
+ with open(fn, "r") as file:
+ lines = file.readlines()
+ file.close()
+ for i in range(len(lines)):
+ lines[i] = lines[i].lower().rstrip("\n")
+ output = []
+ for w in words:
+ if w in lines:
+ output.append(w)
+ for out in output:
+ print(out)