Two-color ball Probability Analysis

Source: Internet
Author: User

Java code
/*
* To change this template, choose Tools | Templates
* And open the template in the editor.
*/

Package test;
Import java. math. BigInteger;
Import java. math. BigDecimal;
/**
* 2011-3-19
* @ Author Jasper
*/
Public class RedandBlue {
Public static void main (String [] args ){
System. out. println ("two-color ball winning probability (6/33 + 1/16 ):");
BigInteger allOdds = getOdds (3, 6). multiply (getOdds (16, 1 ));
BigInteger odds1 = getOdds (6, 6). multiply (getOdds (1, 1 ));
BigInteger odds2 = getOdds (6, 6). multiply (getOdds (15, 1 ));
BigInteger odds3 = getOdds (6, 5). multiply (getOdds (). multiply (getOdds ));
BigInteger odds4 = getOdds (6, 5 ). multiply (getOdds (27,1 )). multiply (getOdds (15,1 )). add (getOdds (6, 4 ). multiply (getOdds (27,2 )). multiply (getOdds (1, 1 )));
BigInteger odds5 = getOdds (6, 4 ). multiply (getOdds (27,2 )). multiply (getOdds (15,1 )). add (getOdds (6, 3 ). multiply (getOdds (27,3 )). multiply (getOdds (1, 1 )));
BigInteger odds6 = getOdds (6, 2 ). multiply (getOdds (27,4 )). multiply (getOdds (1, 1 )). add (getOdds (6, 1 ). multiply (getOdds (27,5 )). multiply (getOdds (1, 1 ))). add (getOdds (27,6 ). multiply (getOdds (1, 1 )));
BigInteger odds00007 = odds1.add (odds2). add (odds3). add (odds4). add (odds5). add (odds6 );
BigInteger odds7 = allOdds. add (odds00007.negate ());
String odds11 = BigDecimal. valueOf (odds1.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 8, BigDecimal. ROUND_HALF_EVEN). toPlainString ();
String odds21 = BigDecimal. valueOf (odds2.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 8, BigDecimal. ROUND_HALF_EVEN). toPlainString ();
String odds31 = BigDecimal. valueOf (odds3.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 8, BigDecimal. ROUND_HALF_EVEN). toPlainString ();
String odds41 = BigDecimal. valueOf (odds4.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 4, BigDecimal. ROUND_HALF_EVEN). toPlainString ();
String odds51 = BigDecimal. valueOf (odds5.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 4, BigDecimal. ROUND_HALF_EVEN). toPlainString ();
String odds61 = BigDecimal. valueOf (odds6.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 4, BigDecimal. ROUND_HALF_EVEN). toPlainString ();
String odds71 = BigDecimal. valueOf (odds7.longValue (). divide (BigDecimal. valueOf (allOdds. longValue (), 4, BigDecimal. ROUND_HALF_EVEN). toPlainString ();

Double check = (new Double (odds11) + (new Double (odds21) + (new Double (odds31) + (new Double (odds41 )) + (new Double (odds51) + (new Double (odds61) + (new Double (odds71 ));
System. out. println ("First Prize (Medium 6 + 1):" + odds1 + "/" + allOdds + "=" + odds11 );
System. out. println ("Second Prize (Medium 6 + 0):" + odds2 + "/" + allOdds + "=" + odds21 );
System. out. println ("third prize (medium 5 + 1) (3000 RMB):" + odds3 + "/" + allOdds + "=" + odds31 );
System. out. println ("four equal prizes (medium 5 + 0 or 4 + 1) (200 RMB):" + odds4 + "/" + allOdds + "=" + odds41 );
System. out. println ("Fifth Prize (medium 4 + 0 or 3 + 1) (10 RMB):" + odds5 + "/" + allOdds + "=" + odds51 );
System. out. println ("Sixth Prize (medium 2 + 1 or 1 + 1 or 0 + 1) (5 RMB: "+ odds6 +"/"+ allOdds +" = "+ odds61 );
System. out. println ("no winning probability:" + odds7 + "/" + allOdds + "=" + odds71 );
System. out. println ("verification result, sum of probabilities" + check );
}

Private static BigInteger getOdds (Integer n, Integer k ){
BigInteger lotteryOdds = BigInteger. valueOf (1 );
For (int I = 1; I <= k; I ++ ){
LotteryOdds = lotteryOdds. multiply (BigInteger. valueOf (n-I + 1). divide (BigInteger. valueOf (I ));
}
Return lotteryOdds;
}
}
Result:
Run:
Two-color ball winning probability (6/33 + 1/16 ):
First prize (6 + 1 in middle): 1/17721088 = 0.00000006
Second prize (Medium 6 + 0): 15/17721088 = 0.00000085
Third prize (medium 5 + 1) (3000 yuan): 162/17721088 = 0.00000914
200 Prize (medium 5 + 0 or 4 + 1) (7695/17721088 yuan): 0.0004 =
Fifth Prize (medium 4 + 0 or 3 + 1) (10 yuan): 137475/17721088 = 0.0078
Sixth Prize (medium 2 + 1 or 1 + 1 or 0 + 1) (5 RMB): 1043640/17721088 = 0.0589
No winning probability: 16532100/17721088 = 0.9329
Verification result. The sum of probabilities is 1.00001005.
Generated successfully (total time: 0 seconds)
 
Good luck!
<! -->

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.