Skip to main content
added 58 characters in body
Source Link
Tbw
  • 2.2k
  • 2
  • 27

Uiua 0.11.0, 26 bytes SBCS

▽:+@\0◿256\+-⬚0↻¯1,∩=@+,@-

Try on Uiua Pad!

Takes a string of + and - and returns the output string. If the input is guaranteed to only contain +-, we can save 2 bytes by replacing ∩=@+,@- with ¬.=@- (and probably more, with a completely different strategy).

Explanation

@-    # push literal character - to stack
@+,   # dup input to top and push +
∩=    # get two arrays with 1s where + and - are
,     # dup the - array to top
⬚0↻¯1 # shift 1 to the left, filling with 0 at front
-     # subtract from the + array
\+    # plus scan: cumulative sums
◿256  # mod 256
+@\0  # add literal character null, converts to ASCII
▽:    # flip the - array to top and apply mask

Uiua 0.11.0, 26 bytes SBCS

▽:+@\0◿256\+-⬚0↻¯1,∩=@+,@-

Try on Uiua Pad!

Takes a string of + and - and returns the output string. If the input is guaranteed to only contain +-, we can save 2 bytes by replacing ∩=@+,@- with ¬.=@-.

Explanation

@-    # push literal character - to stack
@+,   # dup input to top and push +
∩=    # get two arrays with 1s where + and - are
,     # dup the - array to top
⬚0↻¯1 # shift 1 to the left, filling with 0 at front
-     # subtract from the + array
\+    # plus scan: cumulative sums
◿256  # mod 256
+@\0  # add literal character null, converts to ASCII
▽:    # flip the - array to top and apply mask

Uiua 0.11.0, 26 bytes SBCS

▽:+@\0◿256\+-⬚0↻¯1,∩=@+,@-

Try on Uiua Pad!

Takes a string of + and - and returns the output string. If the input is guaranteed to only contain +-, we can save 2 bytes by replacing ∩=@+,@- with ¬.=@- (and probably more, with a completely different strategy).

Explanation

@-    # push literal character - to stack
@+,   # dup input to top and push +
∩=    # get two arrays with 1s where + and - are
,     # dup the - array to top
⬚0↻¯1 # shift 1 to the left, filling with 0 at front
-     # subtract from the + array
\+    # plus scan: cumulative sums
◿256  # mod 256
+@\0  # add literal character null, converts to ASCII
▽:    # flip the - array to top and apply mask
[Edit removed during grace period]
Source Link
Tbw
  • 2.2k
  • 2
  • 27
Source Link
Tbw
  • 2.2k
  • 2
  • 27

Uiua 0.11.0, 26 bytes SBCS

▽:+@\0◿256\+-⬚0↻¯1,∩=@+,@-

Try on Uiua Pad!

Takes a string of + and - and returns the output string. If the input is guaranteed to only contain +-, we can save 2 bytes by replacing ∩=@+,@- with ¬.=@-.

Explanation

@-    # push literal character - to stack
@+,   # dup input to top and push +
∩=    # get two arrays with 1s where + and - are
,     # dup the - array to top
⬚0↻¯1 # shift 1 to the left, filling with 0 at front
-     # subtract from the + array
\+    # plus scan: cumulative sums
◿256  # mod 256
+@\0  # add literal character null, converts to ASCII
▽:    # flip the - array to top and apply mask