Skip to main content
fixed input
Source Link
jaaq
  • 617
  • 6
  • 12

Python 3.8 (pre-release), 168 164 163 126 119125 bytes

l=[p:=0]
n=""
for s in Sinput():
 if(p:=p+1j**(ord(s)%15))in l:x=l.index(p);l=l[:x+1];n=n[:x];p=l[x]
 else:l+=[p];n+=s
exit(n)

Try it online!Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-4135 thanks to @JonathanAllan!

Python 3.8 (pre-release), 168 164 163 126 119 bytes

l=[p:=0]
n=""
for s in S:
 if(p:=p+1j**(ord(s)%15))in l:x=l.index(p);l=l[:x+1];n=n[:x];p=l[x]
 else:l+=[p];n+=s
exit(n)

Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-41 thanks to @JonathanAllan!

Python 3.8 (pre-release), 168 164 163 126 125 bytes

l=[p:=0]
n=""
for s in input():
 if(p:=p+1j**(ord(s)%15))in l:x=l.index(p);l=l[:x+1];n=n[:x];p=l[x]
 else:l+=[p];n+=s
exit(n)

Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-35 thanks to @JonathanAllan!

deleted 8 characters in body
Source Link
jaaq
  • 617
  • 6
  • 12

Python 3.8 (pre-release), 168 164 163 126 bytes126 119 bytes

p=0
l=[p]l=[p:=0]
n=""
for s in S:
 if (p:=p+1j**(ord(s)%15)) in l: l=l[:(x:=lx=l.index(p))+1];n=n[;l=l[:x];p=l[-1]x+1];n=n[:x];p=l[x]
 else: l+=[p];n+=s
exit(n)

Try it online!Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-3741 thanks to @JonathanAllan!

Python 3.8 (pre-release), 168 164 163 126 bytes

p=0
l=[p]
n=""
for s in S:
 if (p:=p+1j**(ord(s)%15)) in l: l=l[:(x:=l.index(p))+1];n=n[:x];p=l[-1]
 else: l+=[p];n+=s
exit(n)

Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-37 thanks to @JonathanAllan!

Python 3.8 (pre-release), 168 164 163 126 119 bytes

l=[p:=0]
n=""
for s in S:
 if(p:=p+1j**(ord(s)%15))in l:x=l.index(p);l=l[:x+1];n=n[:x];p=l[x]
 else:l+=[p];n+=s
exit(n)

Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-41 thanks to @JonathanAllan!

-37 thanks to Jonathan Allan
Source Link
jaaq
  • 617
  • 6
  • 12

Python 3.8 (pre-release), 168 164 163163 126 bytes

p=0
l=[p]
n=""
u=complex(0,1)
for s in S:
    if (p:=p+{'U':u,'D':-u,'R':1,'L':-1}[s]=p+1j**(ord(s)%15)) in l: l=l[:(x:=l.index(p))+1];n=n[:x];p=l[-1]
    else: l+=[p];n+=s
printexit(n)

Try it online!Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-37 thanks to @JonathanAllan!

Python 3.8 (pre-release), 168 164 163 bytes

p=0
l=[p]
n=""
u=complex(0,1)
for s in S:
    if (p:=p+{'U':u,'D':-u,'R':1,'L':-1}[s]) in l: l=l[:(x:=l.index(p))+1];n=n[:x];p=l[-1]
    else: l+=[p];n+=s
print(n)

Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

Python 3.8 (pre-release), 168 164 163 126 bytes

p=0
l=[p]
n=""
for s in S:
 if (p:=p+1j**(ord(s)%15)) in l: l=l[:(x:=l.index(p))+1];n=n[:x];p=l[-1]
 else: l+=[p];n+=s
exit(n)

Try it online!

Assigns a complex number to go up, down, left right on the complex plane. Then iterates over the given path S and either adds the new point to the path in the list of points l and the result string n or if it detected a loop from a previous index up until the current character, it slices the characters and points that created the loops out of the lists.

-37 thanks to @JonathanAllan!

-1 for conventionally defining u, as within a dict declaration brackets are needed when using := operator
Source Link
jaaq
  • 617
  • 6
  • 12
Loading
saved for bytes since the dict is only needed once and doesnt need to be defined as a named variable
Source Link
jaaq
  • 617
  • 6
  • 12
Loading
Source Link
jaaq
  • 617
  • 6
  • 12
Loading