|
Question:
A customer at a 7-11 store selected four items to buy, and was told that the total cost of the four items (without tax) was $7.11. He was curious that the cost was the same as the store name, so he inquired as to how the figure was derived. The clerk said that he had simply multiplied the prices of the four individual items. The customer protested that the four prices should have been ADDED, not MULTIPLIED. The clerk said that that was okay with him, but, the result was still the same: exactly $7.11.
What were the prices of the four items?
Answer:
As this program examines every possibility, we see from the output
of the program, both the solution and the fact that there is only one solution :
The four prices are: 1.20, 1.25, 1.50, 3.16.
As we see 1.20 + 1.25 + 1.50 + 3.16 = 7.11 = 1.20 * 1.25 * 1.50 * 3.16
Here is the solution in the form of a computer program:
main()
{
int a,b,c,d;
for (a=1;a<712;a++)
for (b=1;b<712;b++)
for (c=1;c<712;c++)
for (d=1;d<712;d++)
if (a+b+c+d == 711 && a*b*c*d == 711000000)
printf ("%d %d %d %d",a,b,c,d);
}
Although this method is not very elegant, it does guarantee the solution.
-- Neil Bruce
|