-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimed_test.c
79 lines (64 loc) · 2.08 KB
/
primed_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <math.h>
#include "primed.h"
#define COMP_PARAM 5
int main(int argc, char *argv[]){
if (argc < 2){
printf("err: supply integer at invocation\n");
return 1;
}
ulong num, sqr;
num = atol(argv[1]);
sqr = ceil(sqrt(num));
printf("\n* prime-counting Gaussian approx on %ld: %ld\n", num, pi_approx_Gauss(num));
printf("\n");
printf("* prime-counting on %ld: ", num); fflush(stdout);
printf("%ld\n", pi(num));
printf("\n");
printf("* compiling prime sequence up to %ld:\n", num);
inta prms = primes(num);
/* print last 10 elements only */
print_inta_slice(prms, prms.l-10, prms.l);
wipe_inta(&prms);
printf("\n");
printf("* prime decomposition of %ld: ",num);
inta decomp = decompose(num);
print_inta(decomp);
wipe_inta(&decomp);
printf("\n");
printf("* divizors of %ld:\n",num);
inta divs = divizors(num);
print_inta(divs);
sort_inta(divs);
printf("...quicksort, Hoare partitioned:\n");
print_inta(divs);
wipe_inta(&divs);
printf("\n");
printf("* Example 10-square (1...100) ascii Ulam spiral. Primes coded 1.\n");
ulam_spiral_ascii(10, 1);
printf("\n");
printf("* writing out %ld-square (1...%ld) standard Ulam spiral to ulam.pbm. Primes coded white.\n",sqr,sqr*sqr);
FILE *fp;
fp = fopen("ulam.pbm","w");
ulam_spiral(fp, sqr, 1);
fclose(fp);
printf("\n");
printf("* compiling compositionality values to %ld:\n",num);
inta comps = compositionality(num);
/* print last 40 elements only */
print_inta_slice(comps, comps.l-40, comps.l);
wipe_inta(&comps);
printf("\n");
printf("* Example 10-square (1...100) ascii enhanced composite Ulam spiral.\n");
ulam_spiral_composites_ascii(10);
printf("\n");
printf("* writing out %ld-square (1...%ld) enhanced composite Ulam spiral to ulam_c.ppm.\n",sqr,sqr*sqr);
printf("* writing out color legend to ulam_c_legend.ppm\n");
FILE *lfp;
fp = fopen("ulam_c.ppm","w");
lfp = fopen("ulam_c_legend.ppm","w");
ulam_spiral_composites(fp, cmap_heat_, 0, sqr, COMP_PARAM, lfp, 6);
fclose(fp);
fclose(lfp);
return 0;
}