/*
Fermat Near-Miss Finder
Written by David X. Cohen
May 11, 1995.
This program generated the equation:
1782^12 + 1841^12 = 1922^12
For "The Simpsons" episode "Treehouse Of Horror VI".
Production code: 3F04
Original Airdate: October 30, 1995
*/
#include <stdio.h>
#include <math.h>
main()
{
double x, y, i, z, az, d, upmin, downmin;
upmin = .00001;
downmin = -upmin;
for(x = 51.0; x <= 2554.0; x ++)
{
printf("[%.1f]", x);
for(y = x + 1.0; y <= 2555.0; y ++)
{
for(i = 7.0; i <= 77.0; i ++)
{
z = pow(x, i) + pow(y, i);
if(z == HUGE_VAL) {
printf("[*]");
break; }
z = pow(z, (1.0/i));
az = floor(z + .5);
d = z - az;
if(az == y) break;
if((d < 0.0) && (d >= downmin))
{
downmin = d;
printf("\n%.1f, %.1f, %.1f, = %13.10f\n", x, y, i, z);
}
else if((d >= 0.0) && (d <= upmin))
{
upmin = d;
printf("\n%.1f, %.1f, %.1f, = %13.10f\n", x, y, i, z);
}
if(z < (y + 1.0)) break;
}
}
}
return(1);
}
/*
Fermat Near-Miss Finder
Written by David X. Cohen
February 3, 1998, 3:24 AM.
This program generated the equation:
3987^12 + 4365^12 = 4472^12
For "The Simpsons" episode "The Wizard of Evergreen Terrace".
Production code: 5F21
Original Airdate: September 20, 1998
*/
#include <stdio.h>
#include <math.h>
#define EVEN(x) ((((x) / 2.0) == floor((x) / 2.0)) ? 1 : 0)
main()
{
double x, y, i, z, az, d, upmin;
double bigboy;
int evenx, eveny, evenz;
upmin = .001;
bigboy = 9.99 * pow(10.0, 99.0);
for(x = 2990.0; x <= 4999.0; x ++)
{
printf("[%.0f]", x);
evenx = EVEN(x);
for(y = x + 1.0; y <= 5000.0; y ++)
{
eveny = EVEN(y);
for(i = 7.0; i <= 77.0; i ++)
{
z = pow(x, i) + pow(y, i);
if(z == HUGE_VAL) {
printf("[*]");
break; }
if(z > bigboy) break;
z = pow(z, (1.0/i));
az = floor(z + .5);
d = z - az;
if(az == y) break;
if(d < 0.0) continue;
evenz = EVEN(az);
if(evenx == eveny)
{
if(!evenz) continue;
}
else if(evenz) continue;
if(d <= upmin)
{
upmin = d;
printf("\n%.1f, %.1f, %.1f, = %13.10f\n", x, y, i, z);
}
if(z < (y + 1.0)) break;
}
}
}
return(1);
}