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.
This gives the following garland of the word alfalfa:
alfalfalfalfalfalfalfalfalfalfalfalfalfa…
Write a function degree that takes a word (str) as its argument. If the given word is a garland word, the function must return its degree (int). Otherwise the function must return the value 0.
Write a function garland that takes a word (str) and a number $$r \in \mathbb{N}$$ (int). The function must return a string (str) containing $$r$$ repetitions of the given word. If the given word is a garland word, the first and last $$n$$ letters that two successive repetitions have in common must be repeated only once, where $$n$$ is the degree of the garland word.
>>> 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'