22 lines
768 B
Text
22 lines
768 B
Text
F shortest_abbreviation_length(line, list_size)
|
||
V words = line.split(‘ ’)
|
||
V word_count = words.len
|
||
I word_count != list_size
|
||
X.throw ValueError(‘Not enough entries, expected #. found #.’.format(list_size, word_count))
|
||
|
||
V abbreviation_length = 1
|
||
L
|
||
V abbreviations = Set(words.map(word -> word[0 .< @abbreviation_length]))
|
||
I abbreviations.len == list_size
|
||
R abbreviation_length
|
||
abbreviation_length++
|
||
|
||
F automatic_abbreviations(filename, words_per_line)
|
||
L(line) File(filename).read().split("\n")
|
||
I line.len > 0
|
||
V length = shortest_abbreviation_length(line, words_per_line)
|
||
print(‘#2 #.’.format(length, line))
|
||
E
|
||
print()
|
||
|
||
automatic_abbreviations(‘daysOfWeek.txt’, 7)
|