forked from ademclk/callofcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5f7897
commit 9075ef1
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "solution.hpp" | ||
|
||
std::array<int, 3> pythaTriplet() { | ||
auto sq = [](int x) -> int { | ||
return x * x; | ||
}; | ||
|
||
std::array<int, 3> triplet = {0, 0, 0}; | ||
bool found = false; | ||
// since a + b + c = 1000 | ||
// the max we can go is a = 332, b = 333, c = 334 | ||
for (int a = 1; a <= 332 && !found; a++) { | ||
for (int b = a + 1; b <= 333 + (332 - a) && !found; b++) { | ||
int c = 1000 - (a + b); | ||
|
||
if (sq(a) + sq(b) == sq(c)) { | ||
triplet = {a, b, c}; | ||
found = true; | ||
} | ||
} | ||
} | ||
|
||
return triplet; | ||
} | ||
|
||
/* | ||
int main() { | ||
std::cout << "The values are: "; | ||
for (auto const &val : pythaTriplet()) { | ||
std::cout << val << " "; | ||
} | ||
std::cout << std::endl; | ||
// prints 200 375 425 | ||
return 0; | ||
} | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef PYTHA_TRIP_H | ||
#define PYTHA_TRIP_H | ||
|
||
#include <array> | ||
//#include <iostream> | ||
|
||
std::array<int, 3> pythaTriplet(); | ||
|
||
#endif |