Simple implementation of Joseph Ring algorithm in Java

This paper describes the simple implementation of Joseph Ring algorithm in Java. Share with you for your reference, as follows:

1. Algorithm background:

The Romans captured jotapat, and 41 people hid in a cave to escape the catastrophe. Among the 41 people, the historian Josephus and one of his friends. The remaining 39 people decided to commit collective suicide in order to show that they would not give in to the Romans. We decided on a suicide plan. All the 41 people surrounded the city in a circle. The first person began to count clockwise. Those who did not count 3 immediately committed suicide, and then the next person began to count again

It is still that every person who reports 3 commits suicide immediately, Until everyone kills himself

Joseph and his friends didn't want to commit suicide, so Joseph thought of a plan. They put the same parameters into the suicide plan, but they finally avoided suicide. How did you do it

2. The following code is implemented directly:

The printed result is:

For more information about Java algorithms, readers who are interested can see the topics on this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>