What profession is hidden in the following sequence of words?

FALCON, SEPULCHRE, SATCHEL, BOHEMIAN, PANDEMIC, HEMISPHERE, RESISTOR

The profession we were looking for is ALCHEMIST. We have compiled the sequence of words by first determining the consecutive $$n$$-grams of the word ALCHEMIST for a given $$n \in \mathbb{N}$$ (with $$n > 1$$). For example, for $$n = 3$$ we get the following $$n$$-grams:

ALC, LCH, CHE, HEM, EMI, MIS, IST

We then replace each $$n$$-gram by a word in which it appears.

FALCON, SEPULCHRE, SATCHEL, BOHEMIAN, PANDEMIC, HEMISPHERE, RESISTOR

In doing so, we also ensure that the prefix consisting of the first $$n - 1$$ letters of each $$n$$-gram appears only once in the word. For example, the $$n$$-gram CHE will never be replaced by the word ESCHERICHIA in which the prefix CH is followed by both the letter E and the letter I.

If we would know that ALC is the $$n$$-gram from the first word, we also know that the suffix consisting of the last $$n - 1$$ letters of the $$n$$-gram (LC) appears only once in the second word. Therefore, the letter following that suffix in the second word (H) is the next letter of the profession.

FALCON, SEPULCHRE, SATCHEL, BOHEMIAN, PANDEMIC, HEMISPHERE, RESISTOR

Now that we know that LCH is the $$n$$-gram from the second word, we apply the same strategy to derive the next letter of the profession from the third word. We know that the suffix consisting of the last $$n - 1$$ letters of the $$n$$-gram (CH) appears only once in the third word. The letter following that suffix in the third word (E) is the next letter of the profession.

Similarly, we can use the remaining words to determine the next letters of the profession.

Assignment

A word is represented as a string (str) that only consists of letters. A sequence of words is represented as a sequence (list or tuple) containing words.

Find the profession that we have hidden in a given sequence of words in the way described in the introduction. This is done in the following way:

None of these functions may make a distinction between uppercase and lowercase letters when processing the words passed to them. In addition, the strings (str) they return must always be in uppercase.

Example

>>> next_letter('e', 'HERDSMAN')
'R'
>>> next_letter('LC', 'sepulchre')
'H'
>>> next_letter('onf', 'Teleconference')
'E'
>>> next_letter('EURO', 'DOLLAR')
''
>>> next_letter('LF', 'ALFALFA')
''
>>> next_letter('USE', 'TREEHOUSE')
''

>>> extend('Pe', ['HERDSMAN', 'WONDERFUL', 'FURNACE', 'HELIUM', 'PALINDROME', 'PAPERBACK'])
'PERFUMER'
>>> extend('ALC', ['sepulchre', 'satchel', 'Bohemian', 'pandemic', 'hemisphere', 'resistor'])
'ALCHEMIST'
>>> extend('nonc', ['Teleconference', 'Disinfect', 'Defector', 'Election', 'Section', 'Vibration', 'Pioneer', 'Loner'])
''

>>> profession(['OPERATOR', 'HERDSMAN', 'WONDERFUL', 'FURNACE', 'HELIUM', 'PALINDROME', 'PAPERBACK'])
'PERFUMER'
>>> profession(['falcon', 'sepulchre', 'satchel', 'Bohemian', 'pandemic', 'hemisphere', 'resistor'], length=3)
'ALCHEMIST'
>>> profession(['Nonconformist', 'Teleconference', 'Disinfect', 'Defector', 'Election', 'Section', 'Vibration', 'Pioneer', 'Loner'], 4)
'CONFECTIONER'

Epilogue: dressed for work

The book Fantastic Costumes of Trades & Professions (1965) of parisian engraver Nicolas de Larmessin presents workers clothed in the objects of their calling.

Confectioner
Confectioner
Gardener
Gardener
Perfumer
Perfumer

Resources