RosettaCodeData/Task/Ethiopian-multiplication/Mathematica/ethiopian-multiplication.math
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

7 lines
243 B
Text

IntegerHalving[x_]:=Floor[x/2]
IntegerDoubling[x_]:=x*2;
OddInteger OddQ
Ethiopian[x_, y_] :=
Total[Select[NestWhileList[{IntegerHalving[#[[1]]],IntegerDoubling[#[[2]]]}&, {x,y}, (#[[1]]>1&)], OddQ[#[[1]]]&]][[2]]
Ethiopian[17, 34]