Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: dividing numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53966] Re: [mg53943] dividing numbers
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sat, 5 Feb 2005 03:16:13 -0500 (EST)
  • References: <200502040912.EAA01124@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Here are a couple of solutions, but they only work for one-digit divisors.

f[divisor_][{a_,b_},c_]:=
   {Quotient[10b+c,divisor],Mod[10b+c,divisor]}
longDivide[numerator_,divisor_]:=Rest@FoldList[f[
       divisor],{0,0},IntegerDigits@numerator]
longDivide[20839,9]

{{0,2},{2,2},{3,1},{1,4},{5,4}}

or

Clear[f]
f[divisor_][{a_, b_}, c_] :=
    PadLeft[IntegerDigits[10*b + c, divisor], 2]
longDivide[20839, 9]

{{0, 2}, {2, 2}, {3, 1}, {1, 4}, {5, 4}}

Bobby

On Fri, 4 Feb 2005 04:12:40 -0500 (EST), <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
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Product {for p=2 to infinity} (p^2+1)/(p^2-1) version=3.0.2
  • Next by Date: Re: Graphing sets of linear inequalities
  • Previous by thread: dividing numbers
  • Next by thread: Re: dividing numbers