Trader and the idler

A trader was moving along the road with a basket full of eggs on top of his head. An idler walking on the road dashes the trader thereby breaking the eggs. He is asked by the trader to pay for his loss. Unfortunately, the trader does not know the number of eggs he had in his basket. But remembers the following ,

If counted in pairs, 1 remain

If counted in threes, 2 remain

If counted in fours, 3 remain

If counted in fives, 4 remain

If counted in sixes,5 remain

If counted in sevens, none remain

His basket cannot accomodate more than 150 eggs

What is number of eggs in the traders basket?


The answer is 119.

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

Chris Lewis
Jun 22, 2020

Let x x be the number of eggs. Note that x + 1 x+1 is a multiple of each of 2 , 3 , 4 , 5 , 6 2,3,4,5,6 ; so x + 1 x+1 is a multiple of 60 60 (the least common multiple of these numbers).

Also, x x is a multiple of 7 7 , and x < 150 x<150 . It's easy to see from these constraints that the only possible solution is x = 119 x=\boxed{119} .

Mahdi Raza
Jun 22, 2020

Solution 1: Python code

1
2
3
4
5
import math

for a in range(1, 150):
    if a%2 ==1 and a%3 ==2 and a%4 ==3 and a%5 ==4 and a%6 ==5 and a%7 ==0:
        print(a)

1
119

You're only checking for potential solutions in the range [ 1 , 150 ) [1,150) . What if the solution is greater than 150? You have to keep adjusting your limits then...

A better way to solve this is to use the while loop, and it will stop once a solution is printed out. Try this:

1
2
3
4
5
6
7
8
import math

a = 1
while True:
    if a%2 ==1 and a%3 ==2 and a%4 ==3 and a%5 ==4 and a%6 ==5 and a%7 ==0:
        print(a)
        break
    a += 1

Pi Han Goh - 11 months, 3 weeks ago

Log in to reply

Yeah while loops are great. Here the range was given, then to this is best for an unknown value with no range as well. Thanks!

Mahdi Raza - 11 months, 3 weeks ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...