I came across a little puzzle today and I thought it was really neat:

A customer walked into a 7-11 store and decided to buy four items. When he brought his items to the check-out counter, the cashier rang in the purchases and told the customer that the cost was \$7.11. The customer was curious that the cost of his items was the same as the store name, so he asked the clerk how he came to that price. The clerk responded that he had simply multiplied the prices of the four individual items. The customer protested! He insisted that the four prices should have been added, not multiplied. The clerk said that it was okay with him, but, that the total was still the same: exactly \$7.11.

What were the prices of the four items?

The prices for the 7-11 problem are: \$1.20, \$1.25, \$1.50, and \$3.16

\$7.11 is not the only number which works. There are many other prices which have this property such as \$6.93, \$11.40, but I guess \$7.11 became so popular because of the store with the same name. Note that \$7.11 has a single, unique solution, while this is not necessarily true of other prices with this property. Also there are approximate solutions for \$7.11 such as \$1.01, \$1.15, \$2.41, and \$2.54. These sum to \$7.11 but the product is 7.1100061.

I'm not really sure how the solutions are obtained, but I am currently looking for it. If you have any idea, please /msg me or add it below.

In general, finding four numbers like this is can be expressed by the equation, a+b+c+d=a*b*c*d/1000000, where a, b, c, d are all positive integers.

Unfortunately, I don't know how to solve that, so like all good Computer Scientists, I use the brute force method:

```#include <stdio.h>
#include <limits.h>

int main()
{
unsigned a, b, c, d;

for(a=4; a<=UINT_MAX; a++)
for(b=3; b<=a; b++)
for(c=2; c<=b; c++)
for(d=1; d<=c; d++)
if((a+b+c+d)*1000000 == a*b*c*d)
printf("%4.2f: %4.2f, %4.2f, %4.2f, %4.2f\n",
(a+b+c+d)/100.0,
a/100.0, b/100.0, c/100.0, d/100.0);
return 0;
}
```
Some numbers of note: 6.44, the smallest number that works, 6.75, the first number with two solutions, 7.20, the first number with three solutions, 7.56, the first with four, 8.10, the first with five, ... phew, I could go on all night! (also, 10.89 - that's just a cool number, there)

In case you don't like using precious CPU cycles to solve these types of problems, there is a way of simplifying the solution set greatly:

First, let's multiply everything by 100 to work entirely on integers. That means A+B+C+D = 711, and A*B*C*D = 711000000. Now take the prime factorization of A*B*C*D, which comes out to 2^6 * 3^2 * 5^6 * 79^1. This tells you that each variable must have prime factorizations consisting of only these numbers (eg they are all of the form 2^x * 3^y * 5^z * 79^w). Now you can shorten the number of solutions quite a bit by applying some basic rules of arithmetic.

For the 2^x terms, we know that either 1 or 3 of the terms must be 1 because you need an odd number of odd terms to sum to an odd number. That leaves us with:

64, 1, 1, 1
16, 2, 2, 1
8, 4, 2, 1
4, 4, 4, 1

For the 3^y terms, it only breaks up two ways and both of them are valid.

9, 1, 1, 1
3, 3, 1, 1

For the 5^z terms, you can note that 711 is not a multiple of 5 and therefore k <= 3.

125 125 1 1
125 25 5 1
25 25 25 1

The 79^w terms are (hopefully) obvious.

79 1 1 1

Now that still leaves the problem of reordering all these sets, and testing them. For this, we'll fix the order of the 2's because they can vary the most. The rest add up to a much smaller number than the initial 100,000,000 checks you would have to make. You can only rearrange the 3's set (4+6) = 10 ways. The 5's set is a bit larger at (6 + 24 + 4) = 34 arrangements. The 79's of course have 4 different arrangements. That leaves the total number of checks to be made at 10*34*4*4 = 5440. (The last 4 is for the two's, which are not reordered at all).

Now, having done the math (which probably took longer than just having a computer brute force a solution, but oh well), it's simple to setup the possible solutions for a, b, c, and d. Here's the resulting program in C++:

```#include <iostream.h>

int twos[] = {4,4,4,1, 2,4,8,1, 2,2,16,1, 64,1,1,1};
int threes[] = {3,3,1,1, 3,1,3,1, 3,1,1,3, 1,3,3,1,
1,3,1,3, 1,1,3,3, 9,1,1,1, 1,9,1,1,
1,1,9,1, 1,1,1,9};
int fives[] =  {25,25,25,1, 25,25,1,25, 25,1,25,25, 1,25,25,25,
125,125,1,1, 125,1,125,1, 125,1,1,125, 1,125,125,1,
1,125,1,125, 1,1,125,125, 125,25,5,1, 125,25,1,5,
125,5,25,1,  125,5,1,25,  125,1,25,5, 125,1,5,25,
25,125,5,1,  25,125,1,5,  25,5,125,1,  25,5,1,125,
25,1,125,5, 25,1,5,125, 5,125,25,1,  5,125,1,25,
5,25,125,1,  5,25,125,1,  5,1,125,25, 5,1,25,125,
1,125,25,5,  1,125,5,25,  1,25,125,5,  1,25,125,5,
1,5,125,25, 1,5,25,125};
int sns[] =       {79,1,1,1, 1,79,1,1, 1,1,79,1, 1,1,1,79};

void main() {
int two, three, five, sn, i, total, partialsums[4];
for(two=0; two<16; two+=4) {
for(three=0; three<40; three+=4) {
for(five=0; five<136; five+=4) {
for(sn=0; sn<16; sn+=4) {
total = 0;
for(i=0; i<4; i++) {
partialsums[i] = (twos[two+i] * threes[three+i] *
fives[five+i] * sns[sn+i]);
total += partialsums[i];
}
if(total == 711) {
cout << partialsums[0] << "\t" << partialsums[1] << "\t";
cout << partialsums[2] << "\t" << partialsums[3] << endl;
}
}
}
}
}
}```

Its output is the four numbers, multiplied by 100. And it only took 5440 possible checks (only 1582 if you break out of the loops after finding a solution).

You can also write a small program to solve this a bit more efficiently, by pre-computing all the divisors of 711000000 that are less than 711, and then only trying those options. Something like this would work: ``` ```

``````#include <stdio.h>

int main() {
unsigned int A, B, C, D;
unsigned int Aind, Bind, Cind;
unsigned int divs [61] =
{1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 30, 32, 36,
40, 45, 48, 50, 60, 64, 72, 75, 79, 80, 90, 96, 100, 120, 125, 144,
150, 158, 160, 180, 192, 200, 225, 237, 240, 250, 288, 300, 316, 320,
360, 375, 395, 400, 450, 474, 480, 500, 576, 600, 625, 632};
for(Aind=0, A=divs[0]; Aind<61; Aind++, A=divs[Aind])
for(Bind=0, B=divs[0]; A+B<=709 && Bind<=Aind; Bind++, B=divs[Bind])
for(Cind=0, C=divs[0]; A+B+C<=710 && Cind<=Bind; Cind++, C=divs[Cind]) {
D = 711 - (A+B+C);
if(D<=C) {
if(A*B*C*D == 711000000) {
printf("A: %u, B: %u, C:%u, D: %u\n", A, B, C, D);
}
}
}
return(1);
}
``````
``` ``` This approach finds the result in something like 350 inner loops. If you are interested in a non-brute-force method to solve this problem, you can take a look at the detailed solution in section 2.2 of this paper.

Log in or register to write something here or to contact authors.