-
Notifications
You must be signed in to change notification settings - Fork 0
/
id0008.c
47 lines (34 loc) · 895 Bytes
/
id0008.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
// Licensed under the MIT License.
// Largest Product in a Series
#include "../lib/euler.h"
#include "../lib/series.h"
static long long series_max_product(Series series, int k)
{
long long result = 0;
for (char* it = series->begin; it < series->end - k - 1; it++)
{
long long product = *it;
for (int j = 1; j < k; j++)
{
product *= it[j];
}
if (product > result)
{
result = product;
}
}
return result;
}
int main(void)
{
char buffer[1024];
struct Series series;
clock_t start = clock();
int read = fread(buffer, 1, sizeof buffer, stdin);
euler_assert(read != 0);
euler_assert(!ferror(stdin));
buffer[read] = '\0';
series_from_string(&series, buffer);
long long max = series_max_product(&series, 13);
return euler_submit(8, max, start);
}