A garland word is a word that starts and ends with the same $$n$$ letters (in the same order), for some $$n$$ greater then zero but less than the length of the word. The maximal value $$n$$ for which this holds is called the degree of the garland word. For example, the word alfalfa is a garland word because the first letter of the word is the same as its last letter. However, the degree of the garland word alfalfa is not equal to 1 but 4, because the first four letters of alfalfa are also the same as its last four letters.

The name comes from the fact that we can chain repetitions of a garland word by repeating the first and last $$n$$ letters that two successive repetitions have in common only once, where $$n$$ is the degree of the garland word.

garland word
Alfalfa is a degree-4 garland word.

This gives the following garland of the word alfalfa:

alfalfalfalfalfalfalfalfalfalfalfalfalfa…

Assignment

Example

>>> degree('programmer')
0
>>> degree('ceramic')
1
>>> degree('onion')
2
>>> degree('alfalfa')
4

>>> garland('programmer', 3)
'programmerprogrammerprogrammer'
>>> garland('ceramic', 4)
'ceramiceramiceramiceramic'
>>> garland('onion', 7)
'onionionionionionionion'
>>> garland('alfalfa', 5)
'alfalfalfalfalfalfa'