Commits

Anonymous committed 64d0a56

finished problem 23. could use optimisation

Comments (0)

Files changed (1)

euler/023-abundant.c

+// would be faster to add all the abundant numbers together, and mark
+// an array, but this solution takes ~1minute and the problem won't 
+// be able to scale over 28k anyways.
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#define MAX_TEST 28123
+
 int isabundant(int n) {
 	int i, sum = 1;
 	//printf("%5i: 1 ", n);
 	int i;
 	int *atab;
 	int *jp, *kp;
+	long long sum = 0;
 
-	atab = agenabundants(28123);
+	atab = agenabundants(MAX_TEST);
+
+	for(i=1; i<=MAX_TEST; i++) {
+		int match = 0;
+		for(jp = atab; *jp && *jp < i && !match; jp++) {
+			for(kp = jp; *kp && *kp < i; kp++) {
+				if(*jp + *kp == i) {
+					match = 1;
+					break;
+				}
+			}
+		}
+		if(!match) {
+			sum += i;
+			printf("%6i: %lli\n", i, sum);
+		}
+	}
+
 	return 0;
 }