Jump to content

Ethiopian multiplication: Difference between revisions

Line 196:
| even plier = ethiopicmult' (plier `div` 2) (pliand * 2) acc
| otherwise = ethiopicmult' (plier `div` 2) (pliand * 2) (acc + pliand)</lang>
 
Alternately:
<lang haskell>ethiopicmult :: Integral a => a -> a -> a
ethiopicmult x y = sum [pliand | (plier, pliand) <- rowsNonZero, odd plier]
where rowsNonZero = takeWhile ((/= 0) . fst) rows
rows = zip (iterate (`div` 2) x) (iterate (* 2) y)</lang>
 
'''Usage example''' from the interpreter
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.