Fill in the numbers problem

Composition equation with 1 to 9 the number nine, 0 / eighty + 1 / + 1 / thousand and eighty =1, each number only once
I will only use a stupid method,
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
double t1=clock();
int a,b,c,d,e,f,g,h,i;
for (a=1;a<=9;a++)
for (b=1;b<=9;b++)
for (c=1;c<=9;c++)
for (d=1;d<=9;d++)
for (e=1;e<=9;e++)
for (f=1;f<=9;f++)
for (g=1;g<=9;g++)
for (h=1;h<=9;h++)
for (i=1;i<=9;i++)
if (b != a && c != a && c != b && d != a && d != b && d != c && e != a &&
e != b && e != c && e != d && f != a && f != b && f != c && f != d &&
f != e && g != a && g != b && g != c && g != d && g != e && g != f &&
h != a && h != b && h != c && h != d && h != e && h != f && h != g &&
i != a && i != b && i != c && i != d && i != e && i != f && i != g &&
i != h)

if (a/(10.*b+c)+d/(10.*e+f)+g/(10.*h+i)==1)
printf("%d %d %d %d %d %d %d %d %d\n", a,b,c,d,e,f,g,h,i);
printf("%fs\n", (clock()-t1)/1000);
return 0;
}

Started by King at November 09, 2016 - 5:49 AM

I just want to see if I say I will observe
x + y + z = 1
That is to say the X is less than 1 y is less than 1 Z is less than 1
It will be faster than
There are currently two more than 1 do not meet
Finally and most important point is that you'll find out it is equal to 1
And they are dozens of unexpectedly finally points equal to 1
You put them in a common denominator you'll find out that it is not hard to the molecule is equal to the denominator

Posted by Wendy at November 14, 2016 - 6:38 AM

I this is a stupid way
Look at the
a/(bc) +d/(ef) +g/(hi) =1
Among them:
bc = b*10+c
ef = e*10 + f
hi = h*10+i
Therefore:
a/(bc) +d/(ef) +g/(hi) =1
<==>
a*ef *hi +d *bc*hi + g* bc * ef = bc*ef*hi

The combination, then for each combination, check the a*ef *hi +d *bc*hi + g* BC * EF = = bc*ef*hi is established

Here are 2 bit integer calculation of *2 and *2, the result is 6 digits, not exceeding 32Bits.

Posted by Jay at November 29, 2016 - 7:25 AM

The whole array

Posted by Hobart at December 11, 2016 - 7:43 AM

The 2 floor basic solution. . .
According to the 2 building ideas to write a small program, has unique solution (removal of exchange law)
#include <stdio.h>
#include <algorithm>
#include <functional>
using namespace std ;

int main()
{
	int a[] = {1,2,3,4,5,6,7,8,9};
	do
	{
		int ef = a[4]*10+a[5];
		int bc =a[1]*10+a[2];
		int hi =a[7]*10+a[8];
		if (a[0]*ef*hi+a[3]*bc*hi+a[6]*bc * ef ==bc*ef*hi )
		{
			printf("%d/%d+%d/%d+%d/%d=1\n",a[0],bc,a[3],ef,a[6],hi);
		}
	}while (next_permutation(a,a+9));
	getchar();
	return 0;
}

Posted by Katrina at December 17, 2016 - 8:16 AM