Garlandification
Python, 60 bytes
f=lambda s,i=1:s.find(s[i:])and f(s,i+1)or(len(s)-i)*s[:i]+s
Was hoping for better, but oh well. s.find
works neatly here in place of not s.startswith
.
Retina, 58 bytes
.+
$0#$0
(.*)(.+)#.*\1$
$0#$1#$2-
+`\w#(\w*)-
#$1-$1
#.*-
<empty line>
Each line should go to its own file but you can run the code as one file with the -s
flag.
The four substitution pairs do the followings:
- Duplicate word so we can search for overlaps too.
- Append the word split up at
order
number of characters. - Append the last part
order
times. - Keep the original word and the lastly appended part and drop everything else.
The string states for the example onion
:
onion
onion#onion
onion#onion#on#ion-
onion#onion##ion-ionion
onionionion
Pyth, 19 18 bytes
+z*>Kf!xz>zT1zl>zK
Try it online: Demonstration or Test harness
Explanations:
+z*>Kf!xz>zT1zl>zK implicit: z = input string
f 1 find the first number T >= 1, which satisfies:
>zT all but the first T chars of z
xz index of ^ in z
! == 0
K store in K
the order is length(z) - K
>K z the last K chars
* repeated
l>zK len(all but the last K chars) times
+z insert z at the beginning