Re: dividing numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg53973] Re: [mg53943] dividing numbers
- From: János <janos.lobb at yale.edu>
- Date: Sat, 5 Feb 2005 03:17:13 -0500 (EST)
- References: <200502040912.EAA01124@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Feb 4, 2005, at 4:12 AM, fartous at mail15.com wrote:
> 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
>
In[69]:=
dividend = 20839
divisor = 9
In[71]:=
dd = First[Last[Reap[
While[dividend >
divisor,
currentDividend =
If[First[First[
RealDigits[
dividend]]] >
divisor, First[
First[RealDigits[
dividend]]],
First[RealDigits[
dividend]][[1]]*
10 + First[
RealDigits[
dividend]][[2]]];
currentDividentLength \
= Length[RealDigits[
currentDividend]];
currentQuotient =
Quotient[
currentDividend,
divisor];
currentMod =
Mod[currentDividend,
divisor];
Sow[{currentQuotient,
currentMod}];
dividend = FromDigits[
Join[{currentMod},
Take[RealDigits[
dividend][[1]],
{currentDividentLen\
gth + 1, RealDigits[
dividend][[
2]]}]]]; ]]]]
Out[71]=
{{2, 2}, {3, 1}, {1, 4},
{5, 4}}
In[74]:=
FromDigits[Transpose[dd][[1]]]
Out[74]=
2315
In[76]:=
Last[Transpose[dd][[2]]]/
divisor
Out[76]=
4/9
I am sure there are easier methods for it.
J
ános
----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)
- References:
- dividing numbers
- From: fartous@mail15.com
- dividing numbers