-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid0042.c
41 lines (30 loc) · 781 Bytes
/
id0042.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
// Licensed under the MIT License.
// Coded Triangle Numbers
#include <math.h>
#include "../lib/euler.h"
#include "../lib/string_collection.h"
int main(void)
{
int count = 0;
struct List words;
clock_t start = clock();
euler_ok(list(&words, sizeof(String), 2000));
euler_ok(string_collection_deserialize(&words, stdin));
String* begin = words.items;
String* end = begin + words.count;
for (String* word = begin; word < end; word++)
{
int x = 0;
for (char* p = *word; *p; p++)
{
x += *p - 'A' + 1;
}
if (math_is_polygonal(3, x, NULL))
{
count++;
}
free(*word);
}
finalize_list(&words);
return euler_submit(42, count, start);
}