Ethiopian multiplication: Difference between revisions
Content added Content deleted
Line 1,559: | Line 1,559: | ||
{Show {EthiopicMult 17 34}}</lang> |
{Show {EthiopicMult 17 34}}</lang> |
||
<lang PARI/GP>halve(n)=n\2 |
|||
double(n)=2*n |
|||
{{incorrect|PARI/GP|Task asks for three functions to be defined and used in the solution.}} |
|||
even(n)=!(n%2) |
|||
<lang PARI/GP>multE(a,b)={ |
|||
multE(a,b)={ my(d=0); |
|||
while(a, |
while(a, |
||
if(!even(a), |
|||
d+=b); |
|||
a=halve(a); |
|||
b=double(b)); |
|||
); |
|||
d |
|||
} |
}</lang> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |