A customer goes into a 7-Eleven store and chooses four items. The guy at the checkout charges him $7.11
Intrigued by the coincidence, the customer asks how the total was arrived at, and the clerk tells him he simply multiplied the prices of the four items together.
"Multiplied!" says our hero, "But you're supposed to add!"
The clerk apologises and does the calculation again, but the total is still $7.11
What were the prices of the four items?
$3.16 $1.50 $1.25 $1.20
I asked my nephew this puzzle the other day, but I'd misremembered the number of items, and told him it was three. When he couldn't solve it, I googled the answer, and sent him the four-item solution, but this got me wondering whether there was a solution for three items...
So I wrote a little Python program to check. I found a three-item solution with an exact sum total, but the product total was off by 0.02 cents (0.0002 dollars). By allowing the items to be priced to the tenth of a cent, I got an exact solution.
Can you find the two three-item solutions? You'll need some sort of calculating device, unless you're a much better mathematician than I am.
How do you actually solve it, though? I'm great a maths and at puzzles, but not always great at maths puzzles.
This is as far as I got:
Code:
Let C = 7.11
a + b + c + d = a*b*c*d = C
(a+b+c+d)/C = 1
a/C + b/C + c/C + d/C = 1
1/(b*c*d) + 1/(a*c*d) + 1/(a*b*d) + 1/(a*b*c) = 1
When I got to the 4th step and C fell out of scope, that's when I thought I'm probably not on the right track.
I did google for "sum equals product" but I didn't want to dive too deeply in case I found a spoiler for this specific puzzle. Most of the results I saw had to do with integer solutions anyway, though. (I guess if you scale the problem by 100, we are in the integer space, at least for the 4-item solution)
Let C = 7.11
a + b + c + d = a*b*c*d = C
a = C - b - c - d
b = C - a - c - d
c = C - a - b - d
d = C - a - b - c
Substitute a and solve for b:
b = C - (C - b - c - d) - c - d
= b + c + d - c - d
= b
I mean ...
That the setup didn't involve the product probably should have been a clue that it was bullshit.
You can't solve it using simultaneous equations, because there are fewer equations than unknowns. The search for integer solution(s) (.01 dollars for this puzzle) falls into an area known as Diophantine analysis. There are some good articles on that on Wikipedia and elsewhere.
I'm hopeless at algebra, and always make lots of mistakes, but I like programming, and this problem is small enough to be solved by a simple program in about ten lines of code - probably fewer if you sacrifice clarity for brevity.
My code is a recursive routine. It accepts a sum target, and a product target as parameters, plus the number of unknowns remaining and a start value. There is also a global increment valuč (0.01 for cents in this case). When there are only two unknowns remaining, it tries all the values from start up to sqrt(product_total) for a, calculates sum_total - a for b, and finds the a,b pair where a×b is closest to the product total. It returns the lowest pair and the lowest error. When the recursive routine has more than two unknowns, it runs a loop from start up to nth root of product_total for an item, and calls itself with one less unkown, computing the new sum and product targets by subtracting/dividing the chosen value. It uses the chosen value as the start value for the next level of recursion. The return value of the function is the lowest error found at that recursion level, and a list of the values that result in that error. So the routine just runs the loop, remembering the lowest values found, appends the chosen value to that lowest result list, and returns that up to the outer recursion level.
It quickly arrives at the solution(s) with the lowest error. It found the 'solution' with the 0.0002 dollar product error for the 7-11 three-item case, and by running it again with a step size of 0.001 dollars, it found the exact three-item solution.
The very slight simplification I can offer - I don't think you mentioned this cep - is on prime factors:
Given the prices a, b, c, d as positive (obviously) whole numbers of cents (or tenths of cents in the second case)
then a/100 * b/100 * c/100 * d/100 = 7.11
ie abcd = 711 000 000
so each of a,b,c,d are factors of 711000000, so they are products of its prime factors 2⁶·3˛·5⁶·79 which limits the number of combinations you need to consider (ironically, 7 and 11 cents are not possible).
And of course they are each less than 711 (7110 in the tenths case), so it's not too important if I've miscounted the powers of 10 there.
I shouldn't have said 'exact solution' There is a very slight error, of 0.000012 cents. My Python code was rounding the answers it printed to two decimal places beyond the the increment size, so I didn't see the error.
Here's my 'near-enough-for-accounting-purposes' "solution".
$3.448 $2.967 $0.695
I suppose the obvious bonus problems are:
What resolution is needed for an exact 3-item solution? (May not be possible using just powers of 10, so I suppose third-of-a-cent and other odd fractions might be needed).
(Difficult) Are there any 7-item or 11-item solutions, and if so what resolution is necessary to achieve them.