Holmes brought a bag of fruits into our living room to my astonishment one morning.
Holmes : As I walking past the fruit market, I glanced over 3 ladies, who each bought 3 kinds of fruits: apples, oranges, and pears. In total, the oranges were sold the most, followed by the apples, and then the pears, where all amounts were pairwise coprime. What interested me was that the number of each kind of fruit given to each lady varied from the number 1 to 9 distinctly! I could hardly believe it was an coincidence!
I : Looks like they'll be hosting parties somewhere. I bet they paid different costs then.
Holmes : You lose the bet, Watson. Here, they paid exactly 1 pound and 1 penny! (That added up to 2 4 1 pennies.) Another second coincidence in numbers! The prices for each fruit were in whole pennies with a pear most expensive, followed by an orange, then an apple. I found it hard to put in such equal amount. Anyway, I think you now know how much each apple, orange, and pear cost.
What was the sum of the price of each fruit combined in pennies? (Bonus: Can you work out the amounts of fruits sold as well?)
Inspired by Hens, Pigs, & Ducks
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
My script is posted as a reply to this comment.
Log in to reply
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
This is very, very good, and well written up (I especially like the code in a reply idea!) I went about it a similar, but less efficient way.
I'm not sure if it can be incorporated into your algorithm in any way, but one additional condition is that the determinant of the n i j matrix must be a multiple of 2 4 1 .
I've been trying to come up with an alternative method, but haven't got far with it. It seems the most "unnatural" thing about this problem is in fact the matrix itself. One idea is to start instead from the prices of the fruits. It's easy to put rough bounds on these (for instance, we know that someone buys at least 3 pears, as well as some other fruit, so c p < 8 0 . Someone buys more than 1 5 pieces of fruit, each costing at least as much as an apple, so c a < 1 6 , and so on). Although this search space is larger than the 1 3 6 8 matrices, it is somewhat easier to loop through. The less pretty part is checking the validity of the solutions. Did you have any thoughts about a different approach? (Judging by your solution, you gave this a lot of thought!)
Fun fact: 4 5 pieces of fruit are bought for a total of 7 2 3 pence, at an average price of 1 6 1 5 1 . The price of three pieces of fruit at this rate is 4 8 . 2 pence - not far off!
We will assume the following interpretations:
I will do some linear algebra in fruit space. Let fruit space have three dimensions, one for each kind of fruit, therefore a fruit vector assigns a number to each kind of fruit. Each of the ladies' selection of fruits is a fruit vector v i and also the three prices of the fruits form a fruit vector p . Note that all coordinates of these four vectors must be positive integers. Remark: For the time being I leave the question open as to which coordinate corresponds to which fruit.
The amount that lady i pays then is the inner product ( v i ∣ p ) . Since each lady pays the same amount, we have that ( ( v i − v j ) ∣ p ) = 0 . Therefore the plane spanned by the vectors v 1 − v 2 and v 1 − v 3 must be perpendicular to the price vector p .
This means that we can find the direction of the price vector p using the outer product:
p = c ( v 1 − v 2 ) × ( v 1 − v 3 ) = c ( v 1 × v 2 + v 2 × v 3 + v 3 × v 1 )
It follows that for any of the i: ( v i ∣ p ) = c det ( V )
Here I use a matrix V in which coefficient v i j is the amount of fruit j, bought by lady i.
We know the paid amount is 241d (d is the pre-decimal penny, in the days of Sherlock 1£=20s=240d). Setting c = b a ( c must be a rational number because all other numbers are integers) we now have
2 4 1 b = a det ( V )
Since 241 is a prime number we either have 2 4 1 ∣ det ( V ) or 2 4 1 ∣ a . But in the latter case we will get too large prices.
And since multiples of 241 are too large to be the determinant of 3×3-matices consisting of the 9 different digits 1...9, we will look for such matrices with determinant ± 2 4 1 , and set c = ± 1 (so just forget about a and b).
Writing out the coordinates, we can always find the coordinates of p, once V and c are known:
p 1 = c ( v 1 2 v 2 3 − v 1 3 v 2 2 + v 2 2 v 3 3 − v 2 3 v 3 2 + v 3 2 v 1 3 − v 3 3 v 1 2 ) p 2 = c ( v 1 3 v 2 1 − v 1 1 v 2 3 + v 2 3 v 3 1 − v 2 1 v 3 3 + v 3 3 v 1 1 − v 3 1 v 1 3 ) p 3 = c ( v 1 1 v 2 2 − v 1 2 v 2 1 + v 2 1 v 3 2 − v 2 2 v 3 1 + v 3 1 v 1 2 − v 3 2 v 1 1 )
Using Excel I did a search for 3×3 matrices with coefficients 1...9 and determinant ± 2 4 1 , and tried them out, for example:
V f a i l = ∣ ∣ ∣ ∣ ∣ ∣ 1 2 7 6 3 8 4 9 5 ∣ ∣ ∣ ∣ ∣ ∣ The determinant is +241, so c=+1 and the prices are calculated as above: p 1 = 6 × 9 − 4 × 3 + 3 × 5 − 9 × 8 + 8 × 4 − 5 × 6 = − 1 3 , and similarly we find p 2 = 2 9 and p 3 = 2 0 .
But here we see that one of the prices is negative, so we discard this solution. There are various reasons to discard solutions, because they have to meet these conditions:
Apart from row or column interchangements, only one matrix meets them all, this matrix is: V s u c c e s s = ∣ ∣ ∣ ∣ ∣ ∣ 1 7 3 9 2 4 6 5 8 ∣ ∣ ∣ ∣ ∣ ∣
which has det=-241, so c=-1, and leads to q = ( 1 1 , 1 5 , 1 9 ) and p = ( 1 9 , 1 4 , 1 6 )
So that we have our answer: 1 1 + 1 5 + 1 9 = 4 9
In words:
Bonus:
Problem Loading...
Note Loading...
Set Loading...
I used Python to test out a bunch of cases until I found an answer that worked. I'm hoping someone else has a better method! However, I was able to reduce the number of cases to test by applying the requirements of the problem to the iteration sequence and by introducing a requirement of my own. To begin, the unknowns are the following:
The strategy is to try all possible permutations of n i j and solve for c o , c a , and c p , then determine whether the resulting prices meet the requirements in each case. There are 3 unknowns and 3 equations in each case, so we can solve for the prices using the following system of equations:
⎩ ⎪ ⎨ ⎪ ⎧ n 1 o c o + n 1 a c a + n 1 p c p = 2 4 1 n 2 o c o + n 2 a c a + n 2 p c p = 2 4 1 n 3 o c o + n 3 a c a + n 3 p c p = 2 4 1
There are 9!= 362,880 possible permutations of the numbers 1 through 9 that we could potentially try. However, since solving the system of equations is the most computationally expensive step of the process, I organized my code so as to exhaust all the other requirements on each step before doing so. I was able to reduce the number of times a system was solved from 362,880 to 1,368 by applying the following restrictions:
To check for coprimeness, we can find the prime factors of each sum n 1 j + n 2 j + n 3 j and make sure they have none in common. To find the prime factors, we only have to check for divisibility by primes up to 23 because the maximum sum that can occur is the sum of the 3 largest numbers of fruit purchased: 7+8+9=24.
Finally, after the prices have been found in each case, the following additional requirements must be checked. If they are all met, we have a solution!
Putting this all together, my script gave the output below in about 3 seconds. The script tests all cases even if a solution is found, but it would be faster if it stopped after finding a solution. The script itself is posted below in a comment on a comment because I don't want it to take up too much space.