Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,28 @@
def shortest_abbreviation_length(line, list_size):
words = line.split()
word_count = len(words)
# Can't give true answer with unexpected number of entries
if word_count != list_size:
raise ValueError(f'Not enough entries, expected {list_size} found {word_count}')
# Find the small slice length that gives list_size unique values
abbreviation_length = 1
abbreviations = set()
while(True):
abbreviations = {word[:abbreviation_length] for word in words}
if len(abbreviations) == list_size:
return abbreviation_length
abbreviation_length += 1
abbreviations.clear()
def automatic_abbreviations(filename, words_per_line):
with open(filename) as file:
for line in file:
line = line.rstrip()
if len(line) > 0:
length = shortest_abbreviation_length(line, words_per_line)
print(f'{length:2} {line}')
else:
print()
automatic_abbreviations('daysOfWeek.txt', 7)