Skip to content

emmanuel-h/alibaba

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

alibaba

This is the story for the alibaba problem.

A long time ago, a gang of thieves were robbering a country. The caliph finally achieve to stop them, thanks to Ali Baba. But, among the robbers stand the caliph son. The caliph thought to a scheme to save his son from death, without the people believe he favorised him. So he gave a number to all the robbers, with the number 1 to his son. Then, he asks the robbers leader to sit his companions in a circle, in the order he wants. The caliph will pardon all the people following this rule :

Beginning with the number one (to make sure he saves his son), he will pardon the first person, then he will progress in the circle as many people as the robber just selected number. He will continue like that until he ends on someone already selected. All the selected people will be pardonned, and all the others will be condemned to death.

For example, if the robbers sit in the order 1-3-4-2 (if they are four), the caliph will begin to pardon the robber 1, then he will move one robber forward and pardon the robber number 3, then he will move three robbers forward and he will come across the robber number 1, who has already been selected. So he will stop there. Prisonners 1 and 3 will be pardonned, and prisonners 2 and 4 will be condemned to death.

To this rule, the caliph adds that the robbers' leader cannot be selected, if at least a half of the group hasn't already been selected, so that the leader cannot easily save himself.

So the goal is to say if there is a combination allowing to save everyone, and what it is.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages