Skip to content

Instantly share code, notes, and snippets.

@u840903
Created January 16, 2018 22:12
Show Gist options
  • Save u840903/c3c80fc078b4d06d1ba82226e7245d09 to your computer and use it in GitHub Desktop.
Save u840903/c3c80fc078b4d06d1ba82226e7245d09 to your computer and use it in GitHub Desktop.
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);
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