How to resolve the algorithm Ethiopian multiplication step by step in the Ol programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ethiopian multiplication step by step in the Ol programming language
Table of Contents
Problem Statement
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.
Method:
For example: 17 × 34 Halving the first column: Doubling the second column: Strike-out rows whose first cell is even: Sum the remaining numbers in the right-hand column: So 17 multiplied by 34, by the Ethiopian method is 578.
The task is to define three named functions/methods/procedures/subroutines:
Use these functions to create a function that does Ethiopian multiplication.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ethiopian multiplication step by step in the Ol programming language
Source code in the ol programming language
(define (ethiopian-multiplication l r)
(let ((even? (lambda (n)
(eq? (mod n 2) 0))))
(let loop ((sum 0) (l l) (r r))
(print "sum: " sum ", l: " l ", r: " r)
(if (eq? l 0)
sum
(loop
(if (even? l) (+ sum r) sum)
(floor (/ l 2)) (* r 2))))))
(print (ethiopian-multiplication 17 34))
You may also check:How to resolve the algorithm Simulate input/Keyboard step by step in the Racket programming language
You may also check:How to resolve the algorithm Hough transform step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Test a function step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Terminal control/Coloured text step by step in the REXX programming language
You may also check:How to resolve the algorithm Memory allocation step by step in the Kotlin programming language