-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid0038.c
48 lines (35 loc) · 1012 Bytes
/
id0038.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.
// Pandigital Multiples
#include "../lib/comparer.h"
#include "../lib/euler.h"
#include "../lib/string_builder.h"
int main(void)
{
long max = 918273645l;
struct StringBuilder digits;
struct StringBuilder pandigital;
clock_t start = clock();
euler_ok(string_builder(&digits, 9));
string_builder_from_string(&pandigital, "123456789");
for (int i = 2; i < 10000; i++)
{
string_builder_clear(&digits);
for (int j = 1; digits.length < 9; j++)
{
euler_ok(string_builder_append_format(&digits, "%ld", i * j));
}
long long n = atoll(digits.buffer);
if (n <= max)
{
continue;
}
qsort(digits.buffer, digits.length, 1, char_comparer);
if (!string_builder_equals(&digits, &pandigital))
{
continue;
}
max = n;
}
finalize_string_builder(&digits);
return euler_submit(38, max, start);
}