Skip to content

Commit

Permalink
try to optimize without fixing primes [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 26, 2024
1 parent 7de2b8b commit 98cb62f
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions c/p0012.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,23 @@ divisors?
#include <stdio.h>
#include "include/factors.h"

typedef struct triangle_iterator triangle_iterator;
struct triangle_iterator {
IteratorHead(unsigned long long, triangle_iterator);
unsigned long long current;
unsigned long long idx;
};

unsigned long long advance_triangle_iterator(triangle_iterator *ti) {
// IterationHead(ti);
ti->idx++;
ti->current += ti->idx;
return ti->current;
}

triangle_iterator triangle_iterator0() {
triangle_iterator ret;
IteratorInitHead(ret, advance_triangle_iterator);
ret.current = 0;
ret.idx = 0;
return ret;
}

unsigned long long p0012() {
triangle_iterator ti = triangle_iterator0();
unsigned long long current;
while (true) {
current = next(ti);
unsigned long long current = 1;
for (unsigned int i = 2; ; ++i) {
current += i; // 3, 21, ...
++i;
current += i; // 6, 28, ...
// printf("%llu\n", current);
if (proper_divisor_count(current) > 500)
return current;
++i;
current += i; // 10, 36, ...
if (proper_divisor_count(current) > 500)
return current;
++i;
current += i; // 15, 45, ...
}
return -1;
}

#ifndef UNITY_END
Expand Down

0 comments on commit 98cb62f

Please sign in to comment.