Skip to main content
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

C (gcc),  119 114 112... 111  111110 bytes

Outputs by modifying the input string.

p;f(char*s){for(char*r,*q=s;for(;*s;p*q=s;*q;p?*q++=*s++*s++=*q++:(s=rq=r))for(r=sr=q,p=0;*r?p+=(*r%17?strlen(sq):1)*~-(*r++%5&2):0;);*q=0;;*s=0;}

Try it online!Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (sq and qs respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    

C (gcc),  119 114 112  111 bytes

Outputs by modifying the input string.

p;f(char*s){char*r,*q=s;for(;*s;p?*q++=*s++:(s=r))for(r=s,p=0;*r?p+=(*r%17?strlen(s):1)*~-(*r++%5&2):0;);*q=0;}

Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    

C (gcc),  119 ... 111  110 bytes

Outputs by modifying the input string.

p;f(char*s){for(char*r,*q=s;*q;p?*s++=*q++:(q=r))for(r=q,p=0;*r?p+=(*r%17?strlen(q):1)*~-(*r++%5&2):0;);*s=0;}

Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (q and s respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

C (gcc),  119 114 112  112111 bytes

Outputs by modifying the input string.

p,w;fp;f(char*s){char*r,*q=s;for(;w=strlen(r=s);p;*s;p?*q++=*s++:(s=r))for(r=s,p=0;*r?p+=(*r%17?wstrlen(s):1)*~-(*r++%5&2):0;);*q=0;}

Try it online!Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    

C (gcc),  119 114  112 bytes

Outputs by modifying the input string.

p,w;f(char*s){char*r,*q=s;for(;w=strlen(r=s);p?*q++=*s++:(s=r))for(p=0;*r?p+=(*r%17?w:1)*~-(*r++%5&2):0;);*q=0;}

Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    

C (gcc),  119 114 112  111 bytes

Outputs by modifying the input string.

p;f(char*s){char*r,*q=s;for(;*s;p?*q++=*s++:(s=r))for(r=s,p=0;*r?p+=(*r%17?strlen(s):1)*~-(*r++%5&2):0;);*q=0;}

Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    
saved 2 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

C (gcc),  119 114  114112 bytes

Outputs by modifying the input string.

p,w;f(char*s){char*r,*q=s;for(;w=strlen(sr=s);p?*q++=*s++:(s=r))for(r=s,p=0;*r?p+=(*r%17?w:1)*~-(*r++%5&2):0;);*q=0;}

Try it online!Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    

C (gcc),  119  114 bytes

Outputs by modifying the input string.

p,w;f(char*s){char*r,*q=s;for(;w=strlen(s);p?*q++=*s++:(s=r))for(r=s,p=0;*r?p+=(*r%17?w:1)*~-(*r++%5&2):0;);*q=0;}

Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    

C (gcc),  119 114  112 bytes

Outputs by modifying the input string.

p,w;f(char*s){char*r,*q=s;for(;w=strlen(r=s);p?*q++=*s++:(s=r))for(p=0;*r?p+=(*r%17?w:1)*~-(*r++%5&2):0;);*q=0;}

Try it online!

###How?

The algorithm is the same used in my JS answer with a few differences:

  • We use a for loop instead of a recursive approach.

  • We overwrite the input string with the output. This is safe because what is written is at most as long as what is read, and the meaningful information is always ahead of both the read and the write pointers (s and q respectively).

  • Given the ASCII code c of the move character, we use c % 17 to find out if it's a vertical or horizontal move, and c % 5 & 2 to distinguish between down and up or between left and right.

               | 'D' (68) | 'L' (76) | 'R' (82) | 'U' (85)
      ---------+----------+----------+----------+----------
       % 17    |     0    |     8    |    14    |     0
       % 5 & 2 |     2    |     0    |     2    |     0
    
saved 5 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
added an explanation
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading