Ethiopian multiplication: Difference between revisions
Content added Content deleted
(Added Scheme) |
|||
Line 1,388: | Line 1,388: | ||
12 tests, 12 assertions, 0 failures, 0 errors</pre> |
12 tests, 12 assertions, 0 failures, 0 errors</pre> |
||
=={{header|Scheme}}== |
|||
In Scheme, <code>even?</code> is a standard procedure. |
|||
<lang scheme>(define (halve num) |
|||
(quotient num 2)) |
|||
(define (double num) |
|||
(* num 2)) |
|||
(define (*mul-eth plier plicand acc) |
|||
(cond ((zero? plier) acc) |
|||
((even? plier) (*mul-eth (halve plier) (double plicand) acc)) |
|||
(else (*mul-eth (halve plier) (double plicand) (+ acc plicand))))) |
|||
(define (mul-eth plier plicand) |
|||
(*mul-eth plier plicand 0)) |
|||
(display (mul-eth 17 34)) |
|||
(newline)</lang> |
|||
Output: |
|||
578 |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
{{incorrect|Seed7|The task specifies that examples should have separate functions for doubling, halving, and checking if a number is even.}} |
{{incorrect|Seed7|The task specifies that examples should have separate functions for doubling, halving, and checking if a number is even.}} |