RosettaCodeData/Task/Ethiopian-multiplication/Mathematica/ethiopian-multiplication.math
2023-07-01 13:44:08 -04: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]