Created
January 16, 2018 22:12
-
-
Save u840903/c3c80fc078b4d06d1ba82226e7245d09 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 triple = (target) => | |
for (a in 1 to target / 3) { | |
for (b in a + 1 to target / 2) { | |
let c = target - a - b; | |
if (a * a + b * b === c * c) { | |
Js.log(a * b * c) | |
} | |
} | |
}; | |
triple(1000); |
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 triple = (target) => { | |
let rec next = (a, b) => { | |
let c = target - a - b; | |
if (a * a + b * b === c * c) { | |
a * b * c | |
} else if (b < target / 2) { | |
next(a, b + 1) | |
} else if (a < target / 3) { | |
next(a + 1, a + 2) | |
} else { | |
failwith("Nope."); | |
} | |
}; | |
next(1, 2); | |
}; | |
triple(1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment