Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fullset;
- import java.util.Arrays.*;
- import java.util.Random;
- public class FullSet {
- public static void main(String[] args) {
- //Intialization
- boolean FullSet;
- Random generator = new Random();
- boolean WeHaveANewCard;
- int RandomIntegerBetweenOneAndNrPossibleCards=0;
- double EVcontrib=0;
- int[] NumberFasterThan=new int[3001];
- for (int Iteration=1; Iteration<=1000000; Iteration++){
- int Booster=0;
- int[] Common=new int[111+1];
- int[] Uncommon=new int[80+1];
- int[] Rare=new int[53+1];
- int[] Mythic=new int[16+1];
- int[] DualLand=new int[10+1];
- do{
- //Let's open a booster!
- Booster++;
- //We need to make sure that there are 10 DIFFERENT commons
- int[] CurrentCardsInBooster=new int[11]; for (int SetToZero=1; SetToZero<=10; SetToZero++) {CurrentCardsInBooster[SetToZero]=0;}
- for (int Commons=1; Commons<=10; Commons++){
- do {
- WeHaveANewCard=true;
- RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 111 )+1;
- for (int Check=1; Check<=Commons; Check++){
- if (RandomIntegerBetweenOneAndNrPossibleCards==CurrentCardsInBooster[Check]) {WeHaveANewCard=false;}
- }
- } while (!WeHaveANewCard);
- CurrentCardsInBooster[Commons]=RandomIntegerBetweenOneAndNrPossibleCards;
- Common[RandomIntegerBetweenOneAndNrPossibleCards]++;
- }
- //We need to make sure that there are 3 DIFFERENT uncommons
- CurrentCardsInBooster=new int[4]; for (int SetToZero=1; SetToZero<=3; SetToZero++) {CurrentCardsInBooster[SetToZero]=0;}
- for (int UnCommons=1; UnCommons<=3; UnCommons++){
- do {
- WeHaveANewCard=true;
- RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 80 )+1;
- for (int Check=1; Check<=UnCommons; Check++){
- if (RandomIntegerBetweenOneAndNrPossibleCards==CurrentCardsInBooster[Check]) {WeHaveANewCard=false;}
- }
- } while (!WeHaveANewCard);
- CurrentCardsInBooster[UnCommons]=RandomIntegerBetweenOneAndNrPossibleCards;
- Uncommon[RandomIntegerBetweenOneAndNrPossibleCards]++;
- }
- //We assume that each booster has a mythic rare with probability 1/8
- if (generator.nextDouble()<=0.125) {
- RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 16 )+1;
- Mythic[RandomIntegerBetweenOneAndNrPossibleCards]++;
- }
- else {
- RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 53 )+1;
- Rare[RandomIntegerBetweenOneAndNrPossibleCards]++;
- }
- if (generator.nextDouble()<=(5.0/12.0)) {
- RandomIntegerBetweenOneAndNrPossibleCards=generator.nextInt( 10 )+1;
- DualLand[RandomIntegerBetweenOneAndNrPossibleCards]++;
- }
- //Check if full set is complete
- FullSet=true;
- for (int Com=1; Com<=111; Com++) { if (Common[Com]<1) {FullSet=false;} }
- for (int UNCom=1; UNCom<=80; UNCom++) { if (Uncommon[UNCom]<1) {FullSet=false;} }
- for (int Rar=1; Rar<=53; Rar++) { if (Rare[Rar]<1) {FullSet=false;} }
- for (int Myt=1; Myt<=16; Myt++) { if (Mythic[Myt]<1) {FullSet=false;} }
- for (int Dual=1; Dual<=10; Dual++) { if (DualLand[Dual]<1) {FullSet=false;} }
- } while (FullSet==false);
- //The number of boosters we needed to open in this iteration is stored by Booster
- //For any reasonable integer X, the number of iterations where we needed X boosters or less to complete the set is stored in NumberFasterThan[X]
- for (int X=1; X<=3000; X++){
- if (Booster<=X) {NumberFasterThan[X]++;}
- }
- EVcontrib=EVcontrib+Booster;
- }
- for (int X=1; X<=3000; X++){
- System.out.println(NumberFasterThan[X]);
- }
- System.out.println("Expected number of boosters needed:"+EVcontrib/1000000.0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement