//  -----------------------------------------------------------------
//  -------  Numerische Mathematik   Übung 3.21      ----------------
//  -------  Ib 03                                   ----------------
//  -------  Nachbarzahlen bei Lottoziehungen        ----------------
//  -------                                          ----------------
//  -------  2005 Februar 2     Manfred Vogel        ----------------
//  -----------------------------------------------------------------

public class LottoZahlen
{
	public static void main(String [] args)
	{
		getInfo();
		int max = 100000;
		for (int i = 0; i<max; i++)
		{
			Ziehung tmp = new Ziehung();
		}
		System.out.println("Ziehungen mit Nachbarzahlen bei "+max+" Ziehungen: "+Ziehung.neighbourCntAll);
		System.out.println("ProzentSatz: "+ 100*(float)Ziehung.neighbourCntAll/max +"%");
	}
	
	private static void getInfo()
	{
		String s="";
		s+="\n***************************************************************";
		s+="\n*                                                             *";
		s+="\n*       Berechnen der Wahrscheinlichkeit, dass eine           *";
		s+="\n*            Lottozieung Nachbarzahlen enthält.               *";
		s+="\n*                                                             *";
		s+="\n***************************************************************\n\n";
		System.out.println(s);
	}
}

class Ziehung
{
	public static int neighbourCntAll=0;
	int [] zahlen = new int[6];
	int neighbourCnt=0;
	
	Ziehung()
	{
		for(int i =0; i<6; i++)
		{
			zahlen[i]= (int) (Math.random() *45+0.5);
			for(int j = 0; j<i; j++)
			{
				if( Math.abs(zahlen[i]-zahlen[j])==1)
					this.neighbourCnt++;
				else if(zahlen[i] == zahlen[j])			// Falls eine Zahl 2mal gezogen wird
					i--;	
			}
		}
		if (this.neighbourCnt!=0) Ziehung.neighbourCntAll++;
	}
}

