Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HowLongWillMyGameLastSlightlyBetter {
- public static double probFinishOnTurnNOrLaterRecursive(int turnStop,
- int specialCards, int normalCards) throws IllegalArgumentException {
- if (turnStop > specialCards + normalCards || turnStop < specialCards) {
- throw new IllegalArgumentException(
- "That's just a silly number to ask for since it's out of range.");
- }
- double tempProbability = (double) (specialCards)
- / (double) (specialCards + normalCards);
- if (turnStop == specialCards + normalCards) {
- return tempProbability;
- }
- return (tempProbability + probFinishOnTurnNOrLaterRecursive(turnStop,
- specialCards, normalCards - 1) * (1.0 - tempProbability));
- }
- public static void main(String[] args) {
- int specialCards = 5;
- int normalCards = 16;
- System.out.println("With " + specialCards + " special cards and "
- + normalCards
- + " normal cards in the deck the following is true: ");
- for (int i = specialCards + normalCards; i >= specialCards; i--) {
- double cumulativeProbability = probFinishOnTurnNOrLaterRecursive(i,
- specialCards, normalCards);
- System.out.println("The probability to finish on turn " + i
- + " or later is "
- + (((int) (cumulativeProbability * 10000)) / 100.0) + "%");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement