-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterlock.py~
More file actions
29 lines (25 loc) · 789 Bytes
/
interlock.py~
File metadata and controls
29 lines (25 loc) · 789 Bytes
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
28
29
from list_fns import load_words_append as load_words
from inlist import in_bisect
import time
def find_interlocking_pairs(word_list):
pairs = []
for word in word_list[:25]:
evens = word[::2]
odds = word[1::2]
if in_bisect(word_list, evens) and in_bisect(word_list, odds):
pairs.append(word)
pairs.append(evens)
pairs.append(odds)
return pairs
def main():
word_list = load_words('words.txt')
word_list.sort()
t0 = time.time()
pairs = find_interlocking_pairs(word_list)
t1 = time.time()
print(f"Finished! {int(len(pairs) * (2/3))} interlocking words have been "
f"found in {(t1 - t0):.2f} seconds.")
for word in pairs:
print(word)
if __name__ == '__main__':
main()