Skip to content

Instantly share code, notes, and snippets.

@CarstenKoenig
Last active May 26, 2017 13:51
Show Gist options
  • Save CarstenKoenig/386e75c03e35db10b0ffaa9f0a5a1f3d to your computer and use it in GitHub Desktop.
Save CarstenKoenig/386e75c03e35db10b0ffaa9f0a5a1f3d to your computer and use it in GitHub Desktop.
Russische Bauernmultiplikation / Ancient Egyptian Multiplication
// Algorithmus
// (DE) http://ccd-school.de/coding-dojo/function-katas/russische-bauernmultiplikation/
// (EN) https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication
let rec mul a b =
match a with
| 1 -> b
| a when a <= 0 -> 0
| a when x % 2 = 0 -> mul (a/2) (b*2)
| a -> mul (a/2) (b*2) + b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment