Last active
January 26, 2018 13:55
-
-
Save u840903/bd10c76ac87ba14ca0318c12bb282c24 to your computer and use it in GitHub Desktop.
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 triplet target = | |
let rec next a b = | |
let c = target - a - b in | |
match (a * a + b * b == c * c) with | |
| true -> a * b * c | |
| false when b < target / 2 -> next a (b + 1) | |
| false when a < target / 3 -> next (a + 1) (a + 2) | |
| _ -> 0 in | |
next 1 2 | |
let _ = triplet 1000 (* ==> 31875000 *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment