/* * A189418.c * Calculates the entries of Sloane's A189418 * * Created by Nathaniel Johnston (nathaniel@nathanieljohnston.com) * April 23, 2011 */ #include <math.h> #include <stdio.h> unsigned char pt[256][256]; FILE *file; unsigned char isRhombus (unsigned short a1, unsigned short a2, unsigned short b1, unsigned short b2, unsigned short c1, unsigned short c2, unsigned short d1, unsigned short d2) { unsigned int sd1, sd2, sd3, sd4; sd1 =(a1-b1)*(a1-b1) + (a2-b2)*(a2-b2); sd2 =(b1-d1)*(b1-d1) + (b2-d2)*(b2-d2); sd3 =(c1-d1)*(c1-d1) + (c2-d2)*(c2-d2); sd4 =(a1-c1)*(a1-c1) + (a2-c2)*(a2-c2); if(sd1==sd2 && sd2==sd3 && sd3==sd4)return 1; return 0; } int main () { unsigned short a, b, c, d, a1, a2, b1, b2, c1, c2, d1, d2, maxsz, sz, sz2; unsigned long long numPts; printf("This tool will calculate the entries of Sloane's A189418.\nPlease enter the number of terms to compute (an integer from 1 to 255): "); scanf("%d",&maxsz); numPts = 0; file = fopen("b189418.txt","w"); fprintf(file,"1 0\n"); fclose(file); printf("1 0\n"); for(sz=2;sz<=maxsz;sz++){ numPts = 0; sz2 = sz*sz; for(a=0;a<sz2;a++){ a1 = a % sz; a2 = floor(a/sz); for(b=a+1;b<sz2;b++){ b1 = b % sz; b2 = floor(b/sz); for(c=b+1;c<sz2;c++){ c1 = c % sz; c2 = floor(c/sz); for(d=c+1;d<sz2;d++){ if(isRhombus(a1, a2, b1, b2, c1, c2, d % sz, floor(d/sz))){ numPts++; } } } } } file = fopen("b189418.txt","a"); fprintf(file,"%d %d\n",sz,numPts); fclose(file); printf("%d %d\n",sz,numPts); } printf("Done!"); getchar(); return 0; }