aboutsummaryrefslogtreecommitdiff
path: root/challenge-166/lubos-kolouch/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-166/lubos-kolouch/python')
-rw-r--r--challenge-166/lubos-kolouch/python/ch-1.py27
-rw-r--r--challenge-166/lubos-kolouch/python/ch-2.py29
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-166/lubos-kolouch/python/ch-1.py b/challenge-166/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..fef9376358
--- /dev/null
+++ b/challenge-166/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def hex_words(dictionary_path):
+ hex_map = {"o": "0", "l": "1", "i": "1", "s": "5", "t": "7"}
+ valid_chars = set("abcdef" + "".join(hex_map.values()))
+ words = []
+
+ with open(dictionary_path, "r") as f:
+ for line in f:
+ word = line.strip().lower()
+ if 2 <= len(word) <= 8 and set(word).issubset(valid_chars):
+ words.append("0x" + "".join(hex_map.get(c, c) for c in word))
+
+ return words
+
+
+# path to dictionary file
+dictionary_path = "../../../data/dictionary.txt"
+
+# get hex words
+hex_words = hex_words(dictionary_path)
+
+# print hex words
+for word in hex_words:
+ print(word)
diff --git a/challenge-166/lubos-kolouch/python/ch-2.py b/challenge-166/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..48996dd42e
--- /dev/null
+++ b/challenge-166/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+
+
+def k_directory_diff(dirs):
+ all_files = set()
+ dir_files = {}
+
+ for directory in dirs:
+ files = set(os.listdir(directory))
+ all_files |= files
+ dir_files[directory] = files
+
+ missing_files = {f: [] for f in all_files}
+
+ for directory, files in dir_files.items():
+ for file in all_files:
+ if file not in files:
+ missing_files[file].append(directory)
+
+ for file, directories in missing_files.items():
+ if directories:
+ print(file, "is missing in", ", ".join(directories))
+
+
+dirs = ["dir_a", "dir_b", "dir_c"]
+k_directory_diff(dirs)