Guest User

Untitled

a guest
Jun 4th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. public class Test {
  2.     public static void main(String[] args) throws Throwable {
  3.         final int numWheels = 4;
  4.         final int numSymbols = 8;
  5.         final long threeOfAKindPayout = 17;
  6.         final long fourOfAKindPayout = 200;
  7. //        final long threeOfAKindPayout = 200;
  8. //        final long fourOfAKindPayout = 20_000;
  9.  
  10.         int totalCombinations = numSymbols;
  11.         for (int i = 0; i < numWheels - 1; ++i) {
  12.             totalCombinations *= numSymbols;
  13.         }
  14.  
  15.         System.out.println("Number of symbols: " + numSymbols);
  16.         System.out.println("Number of wheels: " + numWheels);
  17.  
  18.         List<Consumer<Deque<Integer>>> conditionCheckers = new ArrayList<>();
  19.  
  20.         AtomicInteger numThreeOfAKind = new AtomicInteger(0);
  21.         Consumer<Deque<Integer>> threeOfAKindChecker = (values) -> {
  22.             boolean isThreeOfAKind = values.stream()
  23.                     .collect(Collectors.groupingBy(k -> k, counting())).entrySet().stream()
  24.                     .anyMatch(e -> e.getValue() == 3);
  25.             if (isThreeOfAKind) {
  26.                 numThreeOfAKind.incrementAndGet();
  27.                 System.out.print("<3oaK> ");
  28.             }
  29.         };
  30.         conditionCheckers.add(threeOfAKindChecker);
  31.  
  32.         printValues(numWheels, numSymbols, new LinkedList<>(), conditionCheckers);
  33.  
  34.         long totalPayouts = numThreeOfAKind.get() * threeOfAKindPayout + numSymbols * fourOfAKindPayout;
  35.         float averagePayout = totalPayouts / (float) totalCombinations;
  36.  
  37.         System.out.println("Total combinations: " + totalCombinations);
  38.         System.out.println("Total three-of-a-kind: " + numThreeOfAKind.get());
  39.         System.out.println("Total four-of-a-kind: " + numSymbols);
  40.         System.out.println("Average payout: " + averagePayout);
  41.     }
  42.  
  43.     private static void printValues(int wheelsRemaining, int numSymbols, Deque<Integer> values,
  44.             List<Consumer<Deque<Integer>>> conditionCheckers) {
  45.         if (wheelsRemaining == 0) {
  46.             values.stream().forEach(v -> System.out.print(v + " "));
  47.             conditionCheckers.stream().forEach(c -> c.accept(values));
  48.             System.out.println("");
  49.             return;
  50.         }
  51.  
  52.         for (int i = 0; i < numSymbols; ++i) {
  53.             values.push(i + 1);
  54.             printValues(wheelsRemaining - 1, numSymbols, values, conditionCheckers);
  55.             values.pop();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment