You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
822 B
34 lines
822 B
#!/usr/bin/env python |
|
import json |
|
import sys |
|
|
|
alphabet = 'abcdefghijklmnopqrstuvwxyz*' |
|
|
|
srcpath = sys.argv[1] |
|
rarestword = sys.argv[2] |
|
targetpath = sys.argv[3] |
|
|
|
with open(srcpath, 'r') as f: |
|
all_words = json.load(f) |
|
|
|
words = [] |
|
for word in all_words: |
|
words.append(word) |
|
if word == rarestword: break |
|
|
|
# We only care about 5-letter words |
|
words = [word for word in words if len(word) == 5] |
|
|
|
array = [] |
|
for word in words: |
|
number = 0 |
|
for index, letter in enumerate(word): |
|
number += alphabet.index(letter) << (5 * index) |
|
packed = bytes([number & 0xff, (number >> 8) & 0xff, (number >> 16) & 0xff, number >> 24]) |
|
array.append(packed) |
|
|
|
with open(targetpath, 'w') as f: |
|
f.write(f'targets_len equ {len(array)}\n') |
|
f.write('targets:\n') |
|
for packed in array: |
|
f.write(f'\tdb {", ".join(str(byte) for byte in packed)}\n')
|
|
|