1 public static void main(String[] args) {
2 /*
3 * 设有n个人依围成一圈,从第1个人开始报数,数到第m个人出列,
4 * 然后从出列的下一个人开始报数,数到第m个人又出列,
5 * …,如此反复到所有的人全部出列为止。
6 * 设n个人的编号分别为 1, 2, …, n,打印出出
7 * */
8 List<Integer> list = new GetRemainder().getList(30, 5);
9 System.out.println(list);
10 }
11
12 private List<Integer> getList(int lenth, int count) {
13 List<Integer> source = new ArrayList();
14 List<Integer> out = new ArrayList();
15 for (int i = 1; i <= lenth; i++) {
16 source.add(i);
17 }
18 int index = 0;
19 while (source.size() > 0) {
20 //4 8 12 16 20 24
21 System.out.println("index : "+(index + count - 1)+" % "+source.size()+" = "+((index + count - 1) % source.size()));
22 index = (index + count - 1) % source.size();
23 out.add(source.get(index));
24 source.remove(index);
25
26 }
27 return out;
28 }