// example of Monte carlo method of approximation
// start will 48 dice - when a di is 2 remove it
// how many rolls on average until all are gone
// do it 1 million times and take average
import java.io.*;
import java.util.Random;
public class workshop
{
public static void main(String[] args) throws IOException
{final int TIMES = 1000000;
Random r = new Random();
int n;
int diceleft;
double sum = 0;
for (int y=1; y <= TIMES; y++)
{
int roll = 0; // number of rolls to get rid of all dice
int dice = 48; // start with 48 dice
while (dice > 0)
{roll++;
diceleft = dice;
for (int x=1; x <= diceleft; x++)
{n = r.nextInt(6)+1;
if (n==2) // if roll a 2 remove di
dice--;
}
}
sum+= roll;
}
System.out.println(sum/TIMES+" average rolls");
}
}