Ethiopian multiplication: Difference between revisions

→‎{{header|Haskell}}: Removed the multiplication operator from the definition of Ethiopian multiplication :-)
(Added Kotlin)
(→‎{{header|Haskell}}: Removed the multiplication operator from the definition of Ethiopian multiplication :-))
Line 1,652:
=={{header|Haskell}}==
<lang haskell>import Prelude hiding (odd)
import Control.Monad (join)
 
halve, double :: Integral a => aInt -> aInt
halve = (`div` 2)
double = (2 *)
 
odddouble :: Integral a => aInt -> BoolInt
double = (2join *(+)
 
odd :: Int -> Bool
odd = (== 1) . (`mod` 2)
ethiopicmult :: Integral a => a -> a -> a
ethiopicmult a b = sum $ map snd $ filter (odd . fst) $ zip
(takeWhile (>= 1) $ iterate halve a)
(iterate double b)
 
ethiopicmult :: Integral a => aInt -> aInt -> aInt
ethiopicmult a b =
sum $
map snd $
filter (odd . fst) $
zip (takeWhile (>= 1) $ iterate halve a) (iterate double b)
 
main :: IO ()
main = print $ ethiopicmult 17 34 == 17 * 34</lang>
{{Out}}
'''Usage example''' from the interpreter
<pre>*Main> ethiopicmult 17 34
578</pre>
 
=={{header|HicEst}}==
9,655

edits