combinations




Pay Notebook Creator: Salah Ahmed0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

telephone

Get word mappings to strings of numbers

mappings = {
    '0': ' ',
    '1': ' ',
    '2':'ABC',
    '3':'DEF',
    '4':'GHI',
    '5':'JKL',
    '6':'MNO',
    '7':'PQRS',
    '8':'TUV',
    '9':'WXYZ'
}

so 2255 might get "ball" :)

In [1]:
# Crosscompute
number_string_count = 2255
target_folder = '/tmp'
In [2]:
import numpy as np
from itertools import product
from os.path import join

dictionary_text_path = 'dictionary.txt'
mappings = {
    '0': ' ',
    '1': ' ',
    '2':'ABC',
    '3':'DEF',
    '4':'GHI',
    '5':'JKL',
    '6':'MNO',
    '7':'PQRS',
    '8':'TUV',
    '9':'WXYZ'
}
In [3]:
number = str(number_string_count)
dictionary = set()
with open(dictionary_text_path, 'r') as f:
    for l in f:
        dictionary.add(l.strip().lower())
In [4]:
ll = (mappings.get(x, '') for x in number)
permutations = set((''.join(x)).lower() for x in product(*ll))
possible_words = list(permutations & dictionary)
In [5]:
if len(possible_words) > 0:
    possible_words_text_path = join(target_folder, 'possible_words.txt')
    with open(possible_words_text_path, 'w') as f:
        f.writelines(x + '\n' for x in possible_words)  
    print('possible_words_text_path = %s' % possible_words_text_path)
possible_words_text_path = /tmp/possible_words.txt
In [6]:
all_mappings_text_path = join(target_folder, 'all_mappings.txt')
with open(all_mappings_text_path, 'w') as f:
    for l in permutations:
        f.write
    f.writelines(x + '\n' for x in permutations)
print('all_mappings_text_path = %s' % all_mappings_text_path)
all_mappings_text_path = /tmp/all_mappings.txt