Jump to content

Ethiopian multiplication: Difference between revisions

m
Line 2,125:
ethMult :: Int -> Int -> Int
ethMult n m =
( trace
(showDoubles pairs <> " = " <> show v< (<> "\n")
. ((showDoubles pairs <> " = ") <>)
v
. show
)
v = (foldr addedWhereOdd 0 pairs)
where
pairs = zip (unfoldr halved n) (iterate doubled m)
Line 2,138 ⟶ 2,141:
(swap $ quotRem h 2)
| otherwise = Nothing
 
v = foldr addedWhereOdd 0 pairs
addedWhereOdd (d, x) a
| 0 < d = (+) a x
Line 2,163 ⟶ 2,166:
rjust :: Int -> Char -> String -> String
rjust n c s = drop (length s) (replicate n c <> s)
 
 
--------------------------- TEST -------------------------
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.