Ethiopian multiplication: Difference between revisions
Content deleted Content added
Line 190: | Line 190: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>ethiopicmult |
<lang haskell>ethiopicmult :: Integral a => a -> a -> a |
||
ethiopicmult |
ethiopicmult x y = ethiopicmult' x y 0 where |
||
ethiopicmult' 0 _ acc = acc |
|||
ethiopicmult' plier pliand acc |
|||
| even plier = ethiopicmult' (plier `div` 2) (pliand * 2) acc |
|||
| otherwise = ethiopicmult' (plier `div` 2) (pliand * 2) (acc + pliand)</lang> |
|||
'''Usage example''' from the interpreter |
'''Usage example''' from the interpreter |
||
<pre>*Main> ethiopicmult 17 34 |
<pre>*Main> ethiopicmult 17 34 |
||
578</pre> |
578</pre> |
||