-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproblem91.cpp
55 lines (45 loc) · 1.59 KB
/
problem91.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <set>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <vector>
int main(int argc, char** argv)
{
using std::set;
using coordinate = std::tuple<int, int>;
using coordinate_container = set<std::tuple<coordinate, coordinate>>;
std::vector<int> range(51);
std::iota(range.begin(), range.end(), 0);
coordinate_container coordinates;
for(auto x1 : range) {
for(auto y1 : range) {
for(auto x2 : range) {
for(auto y2 : range) {
auto first_tuple = coordinate(x1,y1);
auto second_tuple = coordinate(x2,y2);
auto zero_tuple = coordinate(0,0);
if (first_tuple == zero_tuple || second_tuple == zero_tuple) {
continue;
}
if (first_tuple == second_tuple) {
continue;
}
auto a = x1*x1+y1*y1;
auto b = x2*x2+y2*y2;
auto c = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
bool contains_right_angle =
a + b == c ||
a + c == b ||
b + c == a;
if (! contains_right_angle) {
continue;
}
auto coordinate_pair = std::make_tuple(first_tuple, second_tuple);
coordinates.insert(coordinate_pair);
}
}
}
}
std::cout << coordinates.size()/2 << std::endl;
}