[tpm] russian peasant multiplication

Rick Delaney rick at bort.ca
Wed Jul 22 08:35:02 PDT 2009


On Jul 22 2009, Dave Doyle wrote:
> I know at least one other monger has seen this:
> 
> http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx
> 
> Anyone take a crack at it?

    perl -le '($a,$b)=@ARGV;$s+=$a&1&&$b,$a>>=1,$b<<=1while$a;print$s' 18 23 

I guess it won't work for negative numbers.  Oh well.

-- 
Rick Delaney
rick at bort.ca


More information about the toronto-pm mailing list