Skip to main content
Commonmark migration
Source Link

#MATL, 20 bytes

MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

Explanation

        % Implicitly grab the input
tV      % Duplicate the input and convert to a string
tn      % Duplicate and find the length of this string
w       % Flip the top two stack elements to get us the string again
48-     % Subtract 48 (ASCII 'O'). Yields a negative number for a negative sign
        % and digits otherwise
P       % Flip the resulting array
Z}      % Break the array up so each element is pushed to the stack
t0<?    % If the first character was a negative sign
  x_    % Pop the negative sign off the stack and negate the first digit
]       % End of if
vs      % Vertically concatenate and sum all stack contents
        % Implicitly display the result

#MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

Explanation

        % Implicitly grab the input
tV      % Duplicate the input and convert to a string
tn      % Duplicate and find the length of this string
w       % Flip the top two stack elements to get us the string again
48-     % Subtract 48 (ASCII 'O'). Yields a negative number for a negative sign
        % and digits otherwise
P       % Flip the resulting array
Z}      % Break the array up so each element is pushed to the stack
t0<?    % If the first character was a negative sign
  x_    % Pop the negative sign off the stack and negate the first digit
]       % End of if
vs      % Vertically concatenate and sum all stack contents
        % Implicitly display the result

MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

Explanation

        % Implicitly grab the input
tV      % Duplicate the input and convert to a string
tn      % Duplicate and find the length of this string
w       % Flip the top two stack elements to get us the string again
48-     % Subtract 48 (ASCII 'O'). Yields a negative number for a negative sign
        % and digits otherwise
P       % Flip the resulting array
Z}      % Break the array up so each element is pushed to the stack
t0<?    % If the first character was a negative sign
  x_    % Pop the negative sign off the stack and negate the first digit
]       % End of if
vs      % Vertically concatenate and sum all stack contents
        % Implicitly display the result
added 651 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

#MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

Explanation

        % Implicitly grab the input
tV      % Duplicate the input and convert to a string
tn      % Duplicate and find the length of this string
w       % Flip the top two stack elements to get us the string again
48-     % Subtract 48 (ASCII 'O'). Yields a negative number for a negative sign
        % and digits otherwise
P       % Flip the resulting array
Z}      % Break the array up so each element is pushed to the stack
t0<?    % If the first character was a negative sign
  x_    % Pop the negative sign off the stack and negate the first digit
]       % End of if
vs      % Vertically concatenate and sum all stack contents
        % Implicitly display the result

#MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

#MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

Explanation

        % Implicitly grab the input
tV      % Duplicate the input and convert to a string
tn      % Duplicate and find the length of this string
w       % Flip the top two stack elements to get us the string again
48-     % Subtract 48 (ASCII 'O'). Yields a negative number for a negative sign
        % and digits otherwise
P       % Flip the resulting array
Z}      % Break the array up so each element is pushed to the stack
t0<?    % If the first character was a negative sign
  x_    % Pop the negative sign off the stack and negate the first digit
]       % End of if
vs      % Vertically concatenate and sum all stack contents
        % Implicitly display the result
Post Undeleted by Suever
added 5 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

#MATL, 1820 bytes

ZSG|V!UZtVtnw48-PZ}bb*GVnGvst0<?x_]vs

Try it OnlineTry it Online

All test cases

#MATL, 18 bytes

ZSG|V!UZ}bb*GVnGvs

Try it Online

#MATL, 20 bytes

tVtnw48-PZ}t0<?x_]vs

Try it Online

All test cases

Post Deleted by Suever
Post Undeleted by Suever
added 14 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52
Loading
Post Deleted by Suever
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52
Loading