Last active
November 1, 2022 13:53
-
-
Save AngleWyrm10/c1898b5131967dd1f79d153caf8249c0 to your computer and use it in GitHub Desktop.
three tables of guests
This file contains 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
import java.util.Random; | |
public class Scratchpad { | |
public static void main(String[] args) { | |
// set up our variables | |
Random rng = new Random(); | |
int tries = 100000; | |
int successes = 0; | |
int me, myFriend, sibling1, sibling2; | |
int alone = 0, unwanted = 0; | |
// run the trials | |
for(int thisTry = 0; thisTry < tries; thisTry++){ | |
// everyone rolls a lunch period [0, 1, or 2] | |
me = rng.nextInt(3); | |
myFriend = rng.nextInt(3); | |
sibling1 = rng.nextInt(3); | |
sibling2 = rng.nextInt(3); | |
// skip to the next set of rolls if results were unsatisfactory | |
if(me != myFriend){ | |
alone++; | |
continue; | |
} | |
if( (me == sibling1) || (me == sibling2) ){ | |
unwanted++; | |
continue; | |
} | |
// otherwise we're good | |
successes++; | |
} | |
// display results | |
System.out.println( | |
String.format("Stats out of %s tries\n%s successes (%f), %s alone (%f), %s unwanted (%f); total = %s", | |
tries, successes, (float)successes/tries, | |
alone, (float)alone/tries, | |
unwanted, (float)unwanted/tries, | |
successes + alone + unwanted | |
) | |
); | |
} // main | |
} // Scratchpad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment