Visualize long division with ASCII art Write a program that visualizes long division with ASCII art.  Input consists of two integers, a numerator and a denominator, using the input format of your choice.

Examples:

1234 &divide; 56:

     22
   ----
56|1234
   112
   ---
    114
    112
    ---
      2


1002012 &divide; 12:

     83501
   -------
12|1002012
    96
   ---
     42
     36
     --
      60
      60
      --
        12
        12
        --


0 &divide; 35

   0
   -
35|0


Rules:


Use of the programming language's division operator is allowed.
Use of big integer support is also allowed.
For consistency:

If the quotient is zero, print a single zero at the end of the diving board.
If the remainder is zero, do not print it.
Do not print leading zeros on any numbers.

Excess newlines at the end and trailing spaces to the right are allowed.
Solution with the fewest characters wins.


Limits:


0 &lt;= numerator &lt;= 1072 - 1
1 &lt;= denominator &lt;= 9999999


This implies that the output will never be wider than 80 columns.

Test suite and sample implementation:

You can use long-division.c (gist) to test your program.  It is actually a bash script with a C program inside.  Tweak it to invoke your program in the test suite.  Look at the C code at the bottom to see the reference implementation.  Please let me know if there are any problems with the sample program or test suite.

$ ./long-division.c 10 7
   1
  --
7|10
   7
  --
   3
$ ./long-division.c
PASS 1234 ÷ 56
PASS 1002012 ÷ 12
PASS 1 ÷ 1
--- snip ---

Score: 35 / 35
All tests passed!


Edit: By request, I put the test suite input and expected output into text files (gist).  Sample usage (bash):

cat input | while read nd; do
    ./program $nd |
        sed 's/\s*$//' | sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba'
done &gt; output

diff -u expected output


The weird sed commands filter out trailing newlines and spaces from the program output.
Python 3, 284 257 characters

div.py

n,t=input().split()
d=int(t)
l=lambda x:len(str(x))
s=l(n)
def p(x):print(' '*(l(d)+s-l(x)+1)+str(x))
p(int(n)//d)
p('-'*s)
p(t+'|'+n)
s=z=f=0
while t:
 try:
  while z&lt;d:z=z*10+int(n[s]);s+=1
 except:t=0
 if z*f:p(z)
 if t:f=1;t=z//d*d;p(t);p('-'*l(z));z-=t


Usage: python3 div.py
Input: from keyboard

test.py

import sys
sys.stdin=open('input'); sys.stdout=open('output','w')
for line in open('input'): exec(open('div.py').read())


output matches expected

Versions:
&nbsp;1. 284
&nbsp;2. 257: s,z,f=0,0,0→s=z=f=0; z and f→z*f; better looping; removed a few newlines.