Ethiopian multiplication: Difference between revisions
Content added Content deleted
(→{{header|OCaml}}: incorrect. Program needs to define three functions to halve double and test odd/even as stated in the task description.) |
Underscore (talk | contribs) (→{{header|Haskell}}: Fixed.) |
||
Line 633: | Line 633: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell> |
<lang haskell>import Prelude hiding (odd) |
||
halve, double :: Integral a => a -> a |
|||
halve = (`div` 2) |
halve = (`div` 2) |
||
double = (2 *) |
double = (2 *) |
||
-- 'odd' although included in the Prelude, it is defined here to meet the task specification as: |
|||
⚫ | |||
odd :: Integral a => a -> Bool |
|||
⚫ | |||
ethiopicmult :: Integral a => a -> a -> a |
ethiopicmult :: Integral a => a -> a -> a |
||
ethiopicmult a b = sum $ map snd $ filter (odd . fst) $ zip |
ethiopicmult a b = sum $ map snd $ filter (odd . fst) $ zip |
||
(takeWhile (>= 1) $ iterate halve a) |
(takeWhile (>= 1) $ iterate halve a) |
||
(iterate double b) |
(iterate double b) |
||
main = print $ ethiopicmult 17 34 == 17 * 34</lang> |
|||
'''Usage example''' from the interpreter |
'''Usage example''' from the interpreter |