Russian Peasant Multiplication

by Jul 23, 2009

Small PowerShell exercise taken from the Programming Praxis: Russian Peasant Multiplication contest of WTF (Worse than Failure) implementing the Russian Peasant Multiplication method (for more info see original contest post)

function Invoke-RussianMultiply ([int]$a,[int]$b) { "$a x $b" $r = 0 while($a -ne 1){ $a = $a/2 $b = $b*2 "$a x $b" if ($a%2) {$r+=$b;"`t+$b"} } "result : $r" }
The result… Read the full text.