Python 2, 74 7272 69 bytes
def f(s):
try:eval(exec s.replace(')','),'));print s
except:f(s[-1]+s[s[1:-1]]+s[0])
Tried a similar approach to Jo King's Raku answer by evaluating the bracket string, only difference being an added ,
after every )
so that the expression is valid.
Takes (
and )
instead of [
and ]
.
-2 bytes thanks to Sisyphus, -3 bytes thanks to dingledooper
54 bytes if it's allowed to take ( and ), instead of ( and ) 👀51 bytes if it's allowed to take ( and ), instead of ( and ) 👀