Repeat List Until LongerRepeat List Until Longer
The Challenge
The challenge is simple: given an input list a
and another list b
, repeat a
until it is longer than b
. Call the repeated list ra
. Then the following condition must hold true: len(b) < len(ra) <= len(b) + len(a)
. That is, a
must not be repeated more than is required.
Sample Python Implementation
def repeat(a, b):
ra = a.copy()
while len(b) >= len(ra):
ra += a
return ra
Examples
[1,2,3] [2,4] -> [1,2,3]
[1,2,3] [2,3,4] -> [1,2,3,1,2,3]
[1,2,3] [18,26,43,86] -> [1,2,3,1,2,3]
[2,3,5] [1,2,3,4,5,6,7] -> [2,3,5,2,3,5,2,3,5]
Scoring
This is code-golf, shortest answer in bytes wins. Have fun!