Skip to main content
added 102 characters in body
Source Link
redstarcoder
  • 1.8k
  • 14
  • 28

Python 3 (164 194 186 181 168168 165 bytes)

p=0 w,*x=input().split() for i in x: if'if '-'>i:w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:]p=w.index(i[1:],p)+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Special thanks to Artyer for saving me 13 bytes.

Another thanks to Artyer for saving me another 3 bytes via the beg parameter of index.

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 168 bytes)

p=0 w,*x=input().split() for i in x: if'-'>i:w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Special thanks to Artyer for saving me 13 bytes.

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 168 165 bytes)

p=0 w,*x=input().split() for i in x: if '-'>i:w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w.index(i[1:],p) except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Special thanks to Artyer for saving me 13 bytes.

Another thanks to Artyer for saving me another 3 bytes via the beg parameter of index.

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

added 46 characters in body
Source Link
redstarcoder
  • 1.8k
  • 14
  • 28

Python 3 (164 194 186 181181 168 bytes)

p=0 x=inputw,*x=input().split() w=x[0] for i in x[1:]x:  if i[0]=='+'if'-'>i:w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Special thanks to Artyer for saving me 13 bytes.

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 bytes)

p=0 x=input().split() w=x[0] for i in x[1:]:  if i[0]=='+':w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 168 bytes)

p=0 w,*x=input().split() for i in x: if'-'>i:w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Special thanks to Artyer for saving me 13 bytes.

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 bytes)

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+':w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 
p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+':w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 
p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 bytes)

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+':w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

Python 3 (164 194 186 181 bytes)

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+':w,p=w[:p]+i[1:]+w[p:],0 else: try:p=w[p:].index(i[1:])+p except:p=len(w) w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend Output: HelloThereFriend 

Old answer:

p=0 x=input().split() w=x[0] for i in x[1:]: if i[0]=='+': w=w[:p]+i[1:]+w[p:] p=0 else: p=w[p:].index(i[1:])+p w=w[:p]+w[p:].replace(i[1:],'',1) print(w) 

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh Output: OhHelloTheCowboySays 

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

aaa -b +b would result with aaab because the pointer would go all the way to the end.

Edit2: Fixed.

deleted 4 characters in body
Source Link
redstarcoder
  • 1.8k
  • 14
  • 28
Loading
added 390 characters in body
Source Link
redstarcoder
  • 1.8k
  • 14
  • 28
Loading
added 258 characters in body
Source Link
redstarcoder
  • 1.8k
  • 14
  • 28
Loading
Source Link
redstarcoder
  • 1.8k
  • 14
  • 28
Loading