Matthew Moss wrote:
> ## Long Division (#180)
>
> Your task this week is to perform and display long division.

This isn't thoroughly tested but it seems to work. It supports specifying a 
base and it can display the result either as integer+remainder or as a 
decimal. There's no option to limit the digits as I didn't see the point.
If the number is periodic, it draws a vinculum above the apropriate digits.
Usage: long_divide dividend divisor [--base=BASE] [--remainder]
BASE is the base as a decimal number (both dividend and divisor are specified 
as BASE)
If --remainder is specified, it will print the integer part of the division 
and the remainder, instead of printing the result as a decimal. If the 
division has no remainder, there is no difference.

The code can be used from irb (or another script, if you should want to do 
that for some reason), by requireing it and then using the divide method.
Here's the code:
http://pastie.org/295741

Some sample output from irb:
>> divide(1,3)
    _
  0.3
 +-
3|1
  0
  -
  10
   9
  --
   1
=> nil
>> divide(1,3,2)
     __
   0.01
  +-
11|1
   0
   -
   10
    0
   --
   100
    11
   ---
     1
=> nil
>> divide(10,7)
     ______
   1.428571
 +--
7|10
   7
  --
   30
   28
   --
    20
    14
    --
     60
     56
     --
      40
      35
      --
       50
       49
       --
        10
         7
        --
         3
=> nil
>> divide(1,6)
     _
  0.16
 +-
6|1
  0
  -
  10
   6
  --
   40
   36
   --
    4
>> divide(1,6,10,false)
  0 R1
 +-
6|1
  0
  -
  1
=> nil

-- 
NP: In Flames - Sleepless Again
Jabber: sepp2k / jabber.org
ICQ: 205544826