Ethiopian multiplication: Difference between revisions

no edit summary
m (→‎{{header|Java}}: I think this could loop infinitely if "first" is 0 and i think this might fix that)
No edit summary
Line 51:
*[http://www.bbc.co.uk/dna/h2g2/A22808126 Russian Peasant Multiplication]
*[http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx Programming Praxis: Russian Peasant Multiplication]
 
=={{header|ACL2}}==
<lang Lisp>(include-book "arithmetic-3/top" :dir :system)
 
(defun halve (x)
(floor x 2))
 
(defun double (x)
(* x 2))
 
(defun is-even (x)
(evenp x))
 
(defun multiply (x y)
(if (zp (1- x))
y
(+ (if (is-even x)
0
y)
(multiply (halve x) (double y)))))</lang>
 
=={{header|ActionScript}}==
{{works with|ActionScript|2.0}}
Anonymous user