Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Russian Peasant Multiplication / was question on how
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Dr. Robert Kragler

Posts: 20
Registered: 3/18/08
Russian Peasant Multiplication / was question on how
Posted: Jul 2, 2013 12:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Sun, Jun 30, 2013 at 3:29 AM, <d.a.paxton@gmail.com> wrote:

Hi Dave,
in Wikipedia you will find an explicit example for the Russian Peasant
Multiplication. This algorithm can be simply programed in Mathematica :

Module[{x,y,yS,nD },
x=x0;y=y0; yS=y;
nD=Max @ (Length /@ IntegerDigits @ {x0,y0});
While[x>=1,(Print["x=",pf @ x,"; ","y=",pf @ y,"; ","yS=",pf @ yS ];
If[OddQ[x], yS=yS+y];) ];

See for example


gives as output

x= 27; y= 82; yS= 82
x= 13; y= 164; yS= 246
x= 6; y= 328; yS= 246
x= 3; y= 656; yS= 902
x= 1; y= 1312; yS= 2214

Out[32]= -2214


Robert Kragler
Email : kragler@hs-weingarten.de
URL : http://portal.hs-weingarten.de/web/kragler

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.