Anonymous user
Ethiopian multiplication: Difference between revisions
→{{header|Scala}}
(Rust Code Added) |
|||
Line 3,139:
The first and second are only slightly different and use functional style.
The third uses a for loop to yield the result.
The fourth uses recursion.
<lang scala>
Line 3,153 ⟶ 3,154:
res
}
def ethiopian4(i: Int, j: Int): Int = if (i == 1) j else ethiopian(halve(i), double(j)) + (if (isEven(i)) 0 else j)
def isEven(x:Int)=(x&1)==0
|