-
Notifications
You must be signed in to change notification settings - Fork 0
/
id0068.c
48 lines (39 loc) · 1.14 KB
/
id0068.c
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
// Licensed under the MIT License.
// Magic 5-gon Ring
#include <math.h>
#include "../lib/euler.h"
#include "../lib/permutation_iterator.h"
int main(void)
{
int l[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
unsigned long long max = 0;
struct PermutationIterator it;
clock_t start = clock();
for (permutation_begin(&it, l, 10, sizeof * l, int_comparer);
!it.end;
permutation_next(&it))
{
if (l[0] > l[3] || l[0] > l[5] || l[0] > l[7] || l[0] > l[9] ||
(l[3] != 10 && l[5] != 10 && l[7] != 10 && l[9] != 10))
{
continue;
}
int sum = l[0] + l[1] + l[2];
if (l[2] + l[3] + l[4] != sum || l[4] + l[5] + l[6] != sum ||
l[6] + l[7] + l[8] != sum || l[8] + l[9] + l[1] != sum)
{
continue;
}
unsigned long long value = math_concat(
l[0], l[1], l[2],
l[3], l[2], l[4],
l[5], l[5], l[6],
l[7], l[6], l[8],
l[9], l[8], l[1]);
if (value > max)
{
max = value;
}
}
return euler_submit(68, max, start);
}