Ethiopian multiplication: Difference between revisions

(→‎{{header|J}}: Removed second section as contrary to the comment, it does not obey the letter of the task description as it fails to use the three functions.)
Line 731:
import "fmt"
 
func halve(i int) int { return i >> 1/2 }
 
func double(i int) int { return i*2 << 1}
 
func isEven(i int) bool { return (i % 2) == 0 }
 
func ethMulti(i, j int) (r int) {
for ; i > 0; i, j = halve(i), double(j) {
if !isEven(i) {
r += j
}
}
return
}
return
}
 
func main() {
fmt.Printf("17 ethiopian 34 = %d\n", ethMulti(17, 34))
}
}</lang>
 
=={{header|Haskell}}==
Anonymous user