Last active
August 29, 2015 13:59
-
-
Save battis/10947907 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.facebook.com/david.salmanson.9/posts/10203810541089037 | |
package net.battis.IndianRunMusicalChairs; | |
import java.util.*; | |
public class IndianRunMusicalChairs { | |
private ArrayList<Integer> players; | |
private boolean justSatDown = true; | |
public IndianRunMusicalChairs(int count) { | |
players = new ArrayList<Integer>(); | |
for (int i = 1; i <= count; i++) { | |
players.add(i); | |
} | |
} | |
public void step() { | |
if (justSatDown) { | |
players.add(players.get(0)); | |
} | |
players.remove(0); | |
justSatDown = !justSatDown; | |
} | |
public void iterate() { | |
while (players.size() > 1) { | |
step(); | |
System.out.println(this); | |
} | |
} | |
public String toString( { | |
return players.toString(); | |
} | |
public static void main (String argv[]) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("How many players? "); | |
IndianRun irmc = new IndianRunMusicalChairs(in.nextInt()); | |
System.out.println(irmc); | |
irmc.iterate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment