# Visualize long addition with ASCII art

Totally not inspired by Visualize long division with ASCII art ;)

Your job is to show long hand addition with ASCII art. You solve longhand addition by adding up the columns right to left, placing the value of the ones place in the result, and carrying the tens place over to the top of the next column.

## Input

Input can come basically in any format you want, just as long as you take from 2 to 9 numbers as input.

## Output

The formatting here likely matches how you learned it in school:

carry row
number1
number2
...
+   numX
--------
result


You can have just about any amount of trailing whitespace you want here ;)

## Examples

50, 50

1
50
+50
---
100

1651, 9879

1111
1651
+9879
-----
11530

6489789, 9874, 287

1122
6489789
9874
+    287
--------
6499950

• Visualize long subtraction with ASCII art: Coming straight to you in 6 months Feb 25, 2016 at 1:13
• Not quite, it's on my list ;) Feb 25, 2016 at 1:14
• Actually I was taught to put the carry row under the result.
– Neil
Feb 25, 2016 at 1:15
• How should we handle 9+9+9+9+9+9+9+9+9+9+9+9+9? Feb 25, 2016 at 4:15
• @Downgoat ...you take from 2 to 9 numbers as input... Feb 25, 2016 at 8:34

# Pyth, 59 58 bytes

L.[dJhleSQb:jk_.u/+NsYT.t_MjRTQ00\0djbyMPQXyeQ0\+*J\-ysQ


Way too long. Should golf more.

### Explanation

L                  helper function y = lambda b:
eSQ          largest number in input
l             length as string
h               increment
J                save to J
.[d       b        pad argument with spaces to that length

carry row:
jRTQ           each input to base 10
_M               reverse each result
.t      0          transpose, padding with zeroes
.u               0         cumulative reduce from 0:
sY                      sum digits of column
/    T                     floor-divide by 10
_                           reverse
jk                            join by ""
:                     \0d      replace 0 by space

number rows:
PQ      all input numbers but last one
jb          print on separate lines

last number row:
eQ         last input number
X   0\+      change first char to +

separator row:
J        width of input (saved in helper)
* \-      that many dashes

result row:
sQ      sum of inputs


# Stax, 48 bytes

¢≈3ä⌂♪s♂N#┼DuΦeÑα▼dσÿóYRC├[♂≡α%┴&UZ≤§╟Ω^j╪♪■∞xëa


Run and debug it

) is a lifesaver here, but it still feels too long.

## Batch, 326 bytes

Byte count does not include explanation, of course.

@echo off
set t=%*                            Get the space separated parameters
set t=%t: =+%                       Change the spaces into + signs
set/at=%t%,l=p=1                    Add together, and initialise length and power
set c=                              Carry string
set d=-                             Dash string
:l                                  Loop though each power of 10
set/al+=1,p*=10,s=t/p               Divide the total by the power
for %%n in (%*)do set/as-=%%n/p     Subtract each parameter divided
set c=%s%%c%                        Anything left must have been carried
set d=-%d%                          Add a - to the line of dashes
if %p% leq %t% goto l               Keep going until we run out of powers
echo(%c:0= %                        Delete any zeros in the carry and output it
:i                                  Loop through each parameter
set n=%d:-= %%1                     Pad it with a whole bunch of spaces
call set n=%%n:~-%l%%%              Extract the rightmost characters
if "%2"=="" set n=+%n:~1%           Insert a + before the last parameter
echo %n%                            And output it
shift                               Move to the next parameter
if not "%1"=="" goto i              Until they are all consumed
echo %d%                            Output the line of dashes
echo  %t%                           Output the total (with an indent for the +)


## JavaScript (ES6), 199 bytes

a=>[[...t= +a.reduce((t,n)=>t+n)].map((_,i)=>a.reduce((c,n)=>c-n[i],90+t[i])%10|| ),a=a.map(n=>( .repeat(l=t.length)+n).slice(-l))).join,...a,-.repeat(l),t].join\n.replace(/ (?=.*\n-)/,+)


Where the first \n represents a literal newline character, while the second one is a two-character regexp escape sequence. Explanation:

a=>[                            Accept an array of numbers
[...                           Split the total into digits
t= +a.reduce((t,n)=>t+n)    Calculate the total and add a space
].map((_,i)=>a.reduce((c,n)=>  For each column
c-n[i],90+t[i])               Subtract the column from the total
%10|| ),                    Deduce the carry that was needed
a=a.map(n=>                   For each input value
( .repeat(l=t.length)+n)   Pad to the length of the total
).join,                      Join the carries together
-.repeat(l),                 Append the dividing line
t].join\n                    Append the total and join together
.replace(/ (?=.*\n-)/,+)    Insert the + on the line above the -

The carry calculation works by taking the total digit, prefixing 90, subtracting all the input value digits in that column, and taking the result modulo 10. (The prefix is 90 rather than 9 so that the leading column generates a blank carry space.)