Created
August 23, 2018 01:44
-
-
Save Radcliffe/3fceef030ab9493bd127be594352ae80 to your computer and use it in GitHub Desktop.
Peasant multiplication in Erlang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(multiply). | |
-export([mul/2]). | |
mul(A, B) -> mul(A, B, 0). | |
mul(_, 0, C) -> C; | |
mul(A, B, C) when B rem 2 == 1 -> mul(A, B-1, A+C); | |
mul(A, B, C) -> mul(A + A, B div 2, C). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment