-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler11.cpp
73 lines (62 loc) · 1.38 KB
/
euler11.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//DESCRIPTION: Simply checks every combination.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int array[20][20];
ifstream file("input.txt");
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
file >> array[i][j];
}
}
file.close();
int max_product = 0;
int product;
//check horizontal
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 20; j++)
{
product = array[i][j] * array[i + 1][j] * array[i + 2][j] * array[i + 3][j];
if (product > max_product)
max_product = product;
}
}
//check vertical
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 17; j++)
{
product = array[i][j] * array[i][j + 1] * array[i][j + 2] * array[i][j + 3];
if (product > max_product)
max_product = product;
}
}
//check diagonal down-right
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 17; j++)
{
product = array[i][j] * array[i + 1][j + 1] * array[i + 2][j + 2] * array[i + 3][j + 3];
if (product > max_product)
max_product = product;
}
}
//check diagonal down-left
for (int i = 3; i < 20; i++)
{
for (int j = 0; j < 17; j++)
{
product = array[i][j] * array[i - 1][j + 1] * array[i - 2][j + 2] * array[i - 3][j + 3];
if (product > max_product)
max_product = product;
}
}
cout << max_product;
cin.get();
return 0;
}