Skip to main content
added 976 characters in body
Source Link

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.

How it works:

?        Read the input and push it on the stack.
            (The last number in the list is at the top of the stack.)

[        Start a macro.
 zR        Move the bottom item on the stack to the top, 
              moving the rest of the stack down one item.
 la+sa     Pop the top item on the stack and add it to register a.
              (This number comes from the left part.)
 lFx       Execute F recursively.
]sU      End the macro and name it U.

[        Start a macro.
 lb+sb     Pop the top item on the stack and add it to register b.
              (This number comes from the right part.
              (Note that if the stack is empty so that there's
              nothing to pop, then b is left unchanged.
              This will happen the last time through when the
              original list had an even number of items.)
 z0<     If there's anything still on the stack,
 U         then execute macro U (which adds the bottom item on the
           stack to register a and then executes F recursively).
]dsFx    End the macro, name it F, and execute it.

lblaf    Print a, then print b.

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.

How it works:

?        Read the input and push it on the stack.
            (The last number in the list is at the top of the stack.)

[        Start a macro.
 zR        Move the bottom item on the stack to the top, 
              moving the rest of the stack down one item.
 la+sa     Pop the top item on the stack and add it to register a.
              (This number comes from the left part.)
 lFx       Execute F recursively.
]sU      End the macro and name it U.

[        Start a macro.
 lb+sb     Pop the top item on the stack and add it to register b.
              (This number comes from the right part.)
 z0<     If there's anything still on the stack,
 U         then execute macro U (which adds the bottom item on the
           stack to register a and then executes F recursively).
]dsFx    End the macro, name it F, and execute it.

lblaf    Print a, then print b.

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.

How it works:

?        Read the input and push it on the stack.
            (The last number in the list is at the top of the stack.)

[        Start a macro.
 zR        Move the bottom item on the stack to the top, 
              moving the rest of the stack down one item.
 la+sa     Pop the top item on the stack and add it to register a.
              This number comes from the left part.
 lFx       Execute F recursively.
]sU      End the macro and name it U.

[        Start a macro.
 lb+sb     Pop the top item on the stack and add it to register b.
              This number comes from the right part.
              (Note that if the stack is empty so that there's
              nothing to pop, then b is left unchanged.
              This will happen the last time through when the
              original list had an even number of items.)
 z0<     If there's anything still on the stack,
 U         then execute macro U (which adds the bottom item on the
           stack to register a and then executes F recursively).
]dsFx    End the macro, name it F, and execute it.

lblaf    Print a, then print b.
added 976 characters in body
Source Link

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.

How it works:

?        Read the input and push it on the stack.
            (The last number in the list is at the top of the stack.)

[        Start a macro.
 zR        Move the bottom item on the stack to the top, 
              moving the rest of the stack down one item.
 la+sa     Pop the top item on the stack and add it to register a.
              (This number comes from the left part.)
 lFx       Execute F recursively.
]sU      End the macro and name it U.

[        Start a macro.
 lb+sb     Pop the top item on the stack and add it to register b.
              (This number comes from the right part.)
 z0<     If there's anything still on the stack,
 U         then execute macro U (which adds the bottom item on the
           stack to register a and then executes F recursively).
]dsFx    End the macro, name it F, and execute it.

lblaf    Print a, then print b.

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.

How it works:

?        Read the input and push it on the stack.
            (The last number in the list is at the top of the stack.)

[        Start a macro.
 zR        Move the bottom item on the stack to the top, 
              moving the rest of the stack down one item.
 la+sa     Pop the top item on the stack and add it to register a.
              (This number comes from the left part.)
 lFx       Execute F recursively.
]sU      End the macro and name it U.

[        Start a macro.
 lb+sb     Pop the top item on the stack and add it to register b.
              (This number comes from the right part.)
 z0<     If there's anything still on the stack,
 U         then execute macro U (which adds the bottom item on the
           stack to register a and then executes F recursively).
]dsFx    End the macro, name it F, and execute it.

lblaf    Print a, then print b.
Source Link

dc, 35 bytes

?[zRla+salFx]sU[lb+sbz0<U]dsFxlblaf

Try it online!

Verify the test cases online.

Input is a space-separated list of numbers on stdin.

Output is on stdout, on two lines: the sum of the left part, then the sum of the right part.