Basics about Joseph's Ring:
The Romans captured Giotapat, and 41 people hid in a cave to escape the catastrophe. Among these 41 people, the historian Josephus and one of his friends. In order to show that the remaining 39 people did not surrender to the Romans, they decided to commit suicide collectively. Everyone decided to have a suicide plan. All 41 people besieged the city in a circle, and the first person started to report the number clockwise. The person who did not report the number was 3 immediately committed suicide. Then the next person started to report the number again and still committed suicide for every report the number was 3 immediately..., knowing that everyone committed suicide until they died. Joseph and his friends did not want to commit suicide, so Joseph thought of a plan. They both parameters into the suicide plan, but in the end they avoided suicide. How did it do it
Code sharing:
import java.util.HashMap; import java.util.Map; public class MonkeyKing { public static void main(String args[]) { int n = 100; // Total number of monkeys int m = 3; // Number of outs @SuppressWarnings("rawtypes") Map map = new HashMap(); int nn = 1; // Number of numbers int mm = 1; // Number of numbers System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1; i < n + 1; i++) { map.put(i, i); } while (map.size() > 1) { if (mm == 3) { map.remove(nn); } nn++; if (nn == n + 1) { nn = 1; } if (map.get(nn) != null) { mm++; } if (mm == m + 1) { mm = 1; } } String result = map.values().toString(); System.out.println("Th" + result.substring(1, result.length() - 1) + "Only monkeys are elected Monkey King"); } }