aboutsummaryrefslogtreecommitdiff
path: root/challenge-166/lubos-kolouch/python/ch-1.py
blob: fef93763583dbc9f8be3a3fed41d76b00ff27b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)