Ethiopian multiplication: Difference between revisions

Content added Content deleted
(→‎{{header|R}}: another implementation using another approach (some languages may prefer this approach?))
Line 418: Line 418:


print(ethiopicmult(17, 34, TRUE))</lang>
print(ethiopicmult(17, 34, TRUE))</lang>

Another interesting implementation could be

<lang R>ethiopicmult <- function(a, b) {
plier <- c(a)
plicand <- c(b)
while( plier[ length(plier) ] > 1 ) {
plier <- c(plier, floor(plier[length(plier)]/2))
plicand <- c(plicand, plicand[length(plicand)]*2)
}
return( sum(plicand[ plier %% 2 != 0]) )
}</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==