Apples, Oranges, Pears Riddle

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 3 ladies, who each bought 3 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 1 to 9 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 1 pound and 1 1 penny! (That added up to 241 241 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


The answer is 49.

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.

2 solutions

Eric Nordstrom
May 22, 2019

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 3 prices ( c o c_o for oranges, c a c_a for apples, and c p c_p for pears, in pennies)
  • The 3 amounts of fruit that each of the 3 ladies bought ( n i j n_{ij} , with i i denoting the lady and j j denoting the fruit)

The strategy is to try all possible permutations of n i j n_{ij} and solve for c o c_o , c a c_a , and c p 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 = 241 n 2 o c o + n 2 a c a + n 2 p c p = 241 n 3 o c o + n 3 a c a + n 3 p c p = 241 \begin{cases} n_{1o}c_o+n_{1a}c_a+n_{1p}c_p=241\\ n_{2o}c_o+n_{2a}c_a+n_{2p}c_p=241\\ n_{3o}c_o+n_{3a}c_a+n_{3p}c_p=241 \end{cases}

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:

  • Discard cases in which the total numbers of each fruit are not mutually coprime. This immediately reduces the number of cases to the 49,248 mutually coprime cases (counted with a separate script out of curiosity).
  • Discard cases in which the total number of oranges sold is not greater than the other two or in which the total number of apples is not greater than the pears. This reduces the number of cases by a factor of 3!=6--the number of ways to order the 3 fruits--bringing it down to 8,208.
  • Arbitrarily label Lady 1 as the lady who bought the most oranges, Lady 2 as the one who bought the second-most oranges, and Lady 3 as the one who bought the fewest oranges. Ensure that these are in the correct order; other orders will be repeats of the same solution. This reduces the number of cases by a factor of 6 again, for the final number of 1,368 cases.

To check for coprimeness, we can find the prime factors of each sum n 1 j + n 2 j + n 3 j n_{1j}+n_{2j}+n_{3j} 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!

  • The prices must all be non-negative.
  • Pears must be the most expensive, followed by oranges, then apples.
  • The prices must be in whole pennies.

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
cases tested: 1368
found on case #: 213
solutions found: 1

price of an orange: 16 pennies
price of an apple: 14 pennies
price of a pear: 19 pennies
sum: 49

number of oranges sold: 19
number of oranges sold: 15
number of oranges sold: 11

*confirm amounts paid*
lady 1: 241
lady 2: 241
lady 3: 241

*confirm coprime*
prime factors of 19: {19}
prime factors of 15: {3, 5}
prime factors of 11: {11}

My script is posted as a reply to this comment.

Eric Nordstrom - 2 years ago

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
"""
Eric Nordstrom
Python 3.6.4
Apples, Oranges, Pears Riddle
"""

from sympy import Matrix  # SymPy is a package that can perform operations on symbolic objects such as multi-term expressions, fractions (as opposed to floating points), and matrices. 

primes = (2, 3, 5, 7, 11, 13, 17, 19, 23)  # the possible primes comprising the total quantities of each fruit

def prime_factors(n):
    '''find the prime factors of n'''
    p = set()
    for divisor in primes:
        if n % divisor == 0:
            p.add(divisor)
    return p

total_paid = Matrix([241] * 3)  # total paid by each lady (241 each)
r = range(1, 10)  # numbers 1 thru 9
cases = 0  # to count how many coprime, correctly-ordered cases ultimately get tested
solutions = []  # possible solutions. hopefully there will be only 1.

for n1o in range(3, 10):  # 3 is the lowest number of oranges lady 1 could have bought
    for n2o in range(2, n1o):  # 2 is the lowest number of oranges lady 2 could have bought; restrict to lady 1 buying the most oranges
        for n3o in range(1, n2o):  # restrict to lady 2 buying more oranges than lady 3

            s = {n1o, n2o, n3o}  # record of which numbers 1-9 have been used already
            total_oranges = sum(s)  # for later comparisons
            orange_primes = prime_factors(total_oranges)  # for later comparisons

            for n1a in r:
                if n1a not in s:
                    s.add(n1a)
                    for n2a in r:
                        if n2a not in s:
                            s.add(n2a)
                            for n3a in r:
                                if n3a not in s:

                                    total_apples = n1a + n2a + n3a
                                    if total_apples >= total_oranges:  # restrict to descending order of number of each fruit
                                        continue

                                    apple_primes = prime_factors(total_apples)
                                    if len(apple_primes.intersection(orange_primes)) > 0:  # restrict to coprime totals
                                        continue

                                    s.add(n3a)

                                    for n1p in r:
                                        if n1p not in s:
                                            s.add(n1p)
                                            for n2p in r:
                                                if n2p not in s:
                                                    n3p = 45 - sum(s) - n2p

                                                    total_pears = n1p + n2p + n3p
                                                    if total_pears >= total_apples:  # restrict to descending order of number of each fruit
                                                        continue

                                                    pear_primes = prime_factors(total_pears)
                                                    if len(pear_primes.intersection(orange_primes)) > 0 or len(pear_primes.intersection(apple_primes)) > 0:  # restrict to coprime totals
                                                        continue

                                                    cases += 1
                                                    m = Matrix([[n1o, n1a, n1p],  # the coefficient matrix to solve for prices contains the quantities of each fruit sold to each lady
                                                                [n2o, n2a, n2p],
                                                                [n3o, n3a, n3p]])

                                                    if m.rank() == 3:  # restrict to linearly independent rows
                                                        co, ca, cp = m.row_join(total_paid).rref()[0][:, 3]  # the prices are the elements of the last column of reduced row-eschelon form of augmented matrix
                                                        if type(co).__name__ == 'Integer' and type(ca).__name__ == 'Integer' and type(cp).__name__ == 'Integer' and cp > co and co > ca and co >= 0 and ca >= 0 and cp >= 0:  # restrict to nonzero prices, whole pennies, and correct order of prices. sympy finds the price of each fruit as either an "integer" or a "rational".
                                                            solution = [co, ca, cp, m]
                                                            solutions.append(solution)
                                                            found_on = cases  # to see how many cases were tested before the solution was found

                                            s.remove(n1p)
                                    s.remove(n3a)
                            s.remove(n2a)
                    s.remove(n1a)

print(f'cases tested: {cases}')
print(f'solutions found: {len(solutions)}')

if len(solutions) == 1:

    print(f'found on case #: {found_on}')

    sol = solutions[0]
    m = sol[-1]
    pennies_paid = m * Matrix(sol[:3])
    totals_sold = [sum(m[:, i]) for i in range(3)]

    print()
    for i, fruit in enumerate(('n orange', 'n apple', ' pear')):
        print(f'price of a{fruit}: {sol[i]} pennies')
    print(f'sum: {sum(sol[:3])}')

    print()
    for i in range(3):
        print(f'number of oranges sold: {totals_sold[i]}')

    print()
    print('*confirm amounts paid*')
    for i in range(3):
        print(f'lady {i + 1}: {pennies_paid[i]}')

    print()
    print('*confirm coprime*')
    for i in range(3):
        print(f'prime factors of {totals_sold[i]}: {prime_factors(totals_sold[i])}')

Eric Nordstrom - 2 years ago

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 n_{ij} matrix must be a multiple of 241 241 .

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 3 pears, as well as some other fruit, so c p < 80 c_p<80 . Someone buys more than 15 15 pieces of fruit, each costing at least as much as an apple, so c a < 16 c_a<16 , and so on). Although this search space is larger than the 1368 1368 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: 45 45 pieces of fruit are bought for a total of 723 723 pence, at an average price of 16 1 15 16\tfrac{1}{15} . The price of three pieces of fruit at this rate is 48.2 48.2 pence - not far off!

Chris Lewis - 2 years ago
K T
May 24, 2019

We will assume the following interpretations:

  • each kind of fruit has a fixed price per piece which is a positive integer number of pence.
  • 'all amounts' refers to the three sales amounts per type of fruit.

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 \vec{v_i} and also the three prices of the fruits form a fruit vector p \vec{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 ) (\vec{v_i}| \vec{p}) . Since each lady pays the same amount, we have that ( ( v i v j ) p ) = 0 ((\vec{v_i}-\vec{v_j})| \vec{p})=0 . Therefore the plane spanned by the vectors v 1 v 2 \vec{v_1}-\vec{v_2} and v 1 v 3 \vec{v_1}-\vec{v_3} must be perpendicular to the price vector p \vec{p} .

This means that we can find the direction of the price vector p \vec{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 ) \vec{p} = c (\vec{v_1}-\vec{v_2}) × (\vec{v_1}-\vec{v_3})= c (\vec{v_1}× \vec{v_2} + \vec{v_2}× \vec{v_3} + \vec{v_3} × \vec{v_1})

It follows that for any of the i: ( v i p ) = c det ( V ) (\vec{v_i}|\vec{p})= c \det (V)

Here I use a matrix V in which coefficient v i j v_{ij} 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 = a b c=\frac{a}{b} ( c must be a rational number because all other numbers are integers) we now have

241 b = a det ( V ) 241b = a \det (V)

Since 241 is a prime number we either have 241 det ( V ) 241|\det(V) or 241 a 241|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 ± 241 \pm 241 , and set c = ± 1 c=\pm1 (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 12 v 23 v 13 v 22 + v 22 v 33 v 23 v 32 + v 32 v 13 v 33 v 12 ) p_1=c(v_{12}v_{23}- v_{13}v_{22} + v_{22}v_{33}- v_{23}v_{32} + v_{32}v_{13}- v_{33}v_{12}) p 2 = c ( v 13 v 21 v 11 v 23 + v 23 v 31 v 21 v 33 + v 33 v 11 v 31 v 13 ) p_2=c(v_{13}v_{21}- v_{11}v_{23} + v_{23}v_{31}- v_{21}v_{33} + v_{33}v_{11}- v_{31}v_{13}) p 3 = c ( v 11 v 22 v 12 v 21 + v 21 v 32 v 22 v 31 + v 31 v 12 v 32 v 11 ) p_3=c(v_{11}v_{22}- v_{12}v_{21} + v_{21}v_{32}- v_{22}v_{31} + v_{31}v_{12}- v_{32}v_{11})

Using Excel I did a search for 3×3 matrices with coefficients 1...9 and determinant ± 241 \pm241 , and tried them out, for example:

V f a i l = 1 6 4 2 3 9 7 8 5 V_{fail} = \left| \begin{array}{ccc} 1 & 6 & 4 \\ 2 & 3 & 9 \\ 7 & 8 & 5 \end{array} \right| 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 = 13 p_1=6×9-4×3 +3×5-9×8+8×4-5×6=-13 , and similarly we find p 2 = 29 p_2=29 and p 3 = 20 p_3=20 .

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:

  • the determinant is ± 241 \pm241
  • the price for each type of fruit is a positive integer
  • each price is different
  • sales amounts are pairwise coprime
  • the least sold fruit is the most expensive, the price of the most sold fruit is between the other prices.

Apart from row or column interchangements, only one matrix meets them all, this matrix is: V s u c c e s s = 1 9 6 7 2 5 3 4 8 V_{success} = \left| \begin{array}{ccc} 1 & 9 & 6 \\ 7 & 2 & 5 \\ 3 & 4 & 8 \end{array} \right|

which has det=-241, so c=-1, and leads to q = ( 11 , 15 , 19 ) \vec{q} = (11, 15, 19) and p = ( 19 , 14 , 16 ) \vec{p} = (19, 14, 16)

So that we have our answer: 11 + 15 + 19 = 49 11+15+19 = \boxed{49}

In words:

  • pears: sold 11 pieces for 19d each
  • apples sold 15 sold pieces for 14d each
  • oranges: sold 19 pieces for 16d each.

Bonus:

  • Lady 1 bought 1 pear, 9 apples and 6 oranges
  • Lady 2 bought 7 pears, 2 apples, 5 oranges
  • Lady 3 bought 3 pears, 4 apples, 8 oranges.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...