Ethiopian multiplication: Difference between revisions
Content deleted Content added
Correct parameter type |
added factor implemenation |
||
Line 536: | Line 536: | ||
return ab |
return ab |
||
}</lang> |
}</lang> |
||
=={{header|Factor}}== |
|||
<lang factor>USING: arrays kernel math multiline sequences ; |
|||
IN: ethiopian-multiplication |
|||
/* |
|||
This function is built-in |
|||
: odd? ( n -- ? ) 1 bitand 1 number= ; |
|||
*/ |
|||
: double ( n -- 2*n ) 2 * ; |
|||
: halve ( n -- n/2 ) 2 /i ; |
|||
: ethiopian-mult ( a b -- a*b ) |
|||
[ 0 ] 2dip |
|||
[ dup 0 > ] [ |
|||
[ odd? [ + ] [ drop ] if ] 2keep |
|||
[ double ] [ halve ] bi* |
|||
] while 2drop ;</lang> |
|||
=={{header|FALSE}}== |
=={{header|FALSE}}== |