MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: dividing numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53960] Re: [mg53943] dividing numbers
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 5 Feb 2005 03:15:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com


>-----Original Message-----
>From: fartous at mail15.com [mailto:fartous at mail15.com] 
To: mathgroup at smc.vnet.net
>Sent: Friday, February 04, 2005 10:13 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg53960] [mg53943] dividing numbers
>
>Hi
>i have a small question
>we know how to divide numbers using the elementary school Long 
>procedure, suppose mathematica is a small child and i want him 
>to show me his procedure step by step such as this:
>input:  20839 ,  9
>output:
>1-  2/9 ->0   mod=2
>2- 20/9 ->2   mod=2
>3- 28/9 ->3   mod=1
>4- 13/9 ->1   mod=4
>5- 49/9 ->5   mod=4
>so the final result will be 2315+(4/9)
>how to implement this in mathematica
>jack
>
>

Just to illustrate the idea:

In[1]:= 
divident = IntegerDigits[20839]
divisor = 9;
Out[1]= {2, 0, 8, 3, 9}

In[5]:=
step = ({a, b} = Through[{Quotient, Mod}[
        c = 10*#1[[1]] + #2, divisor]]; 
     Print[c, "/", divisor, " -> ", a, "  mod = ", b]; 
     {b, 10*#1[[2]] + a}) & ; 

In[6]:=
final = Print["So the final result will be ", #1[[2]], 
     " + ", #1[[1]]/divisor] & ; 


In[7]:=
final[Fold[step, {0, 0}, divident]]

>From In[7]:= 2/9 -> 0  mod = 2
>From In[7]:= 20/9 -> 2  mod = 2
>From In[7]:= 28/9 -> 3  mod = 1
>From In[7]:= 13/9 -> 1  mod = 4
>From In[7]:= 49/9 -> 5  mod = 4
>From In[7]:= So the final result will be 2315 + 4/9


--
Hartmut Wolf


  • Prev by Date: Re: Graphing sets of linear inequalities
  • Next by Date: Re: Nonlinear Fittings: range / boundaries are not working :(
  • Previous by thread: Re: dividing numbers
  • Next by thread: multiprocessor vs cache/memory