Last active
August 29, 2015 14:11
-
-
Save khzaw/671527263e46ead40c02 to your computer and use it in GitHub Desktop.
Recursive exponentiation
This file contains 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
let (<>) a b = | |
let rec timesPrime a b acc = match b with | |
| 0 -> acc | |
| _ -> timesPrime a (pred b) (acc+a) | |
in timesPrime a b 0 | |
;; | |
let rec pow x = function | |
| 0 -> 1 | |
| n when n mod 2 = 0 -> | |
let x = pow x (n/2) in | |
(x <> x) | |
| n -> (pow x (n-1) <> x) | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment