The Moroccan Spices Box Set Puzzle

In the heart of the medina of Marrakech, you will find one of the largest and most colourful souks in Morocco. In this souk, you will find merchants selling traditional clothing, multicoloured carpets, pottery, jewellery, antiques, lanterns, spices, etc. On the spice square, Halim, a merchant of Moroccan spices, would like to sell different box sets of jars containing various spices. Halim has a collection of 10 jars and would like to create three box sets of exactly 250g each.

Could you help Halim create these three box sets using the following 10 jars. Each set must contain exactly 250g of spices. (Drag and drop the following jars to create three groups)

View Solution
There are more than one solution to this puzzle. Here is one possible solution:

Python Challenge

To help Halim to create similar box sets in the future, we would like to create a Python algorithm that suggests a possible solution for any given set of jars.

We will use a list to store the collection of jars available. For instance, using the current set of 10 jars, our list would be as follows:
jars = [150,20,20,10,80,130,110,90,100,40]

The aim of this challenge is to use a backtracking / recursive algorithm to work out a possible solution for this puzzle by creating three lists of jars, using the values from the above jars list to create 3 box sets of exactly 250g each.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 27

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,