Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String[] args) throws Throwable {
- final int numWheels = 4;
- final int numSymbols = 8;
- final long threeOfAKindPayout = 17;
- final long fourOfAKindPayout = 200;
- // final long threeOfAKindPayout = 200;
- // final long fourOfAKindPayout = 20_000;
- int totalCombinations = numSymbols;
- for (int i = 0; i < numWheels - 1; ++i) {
- totalCombinations *= numSymbols;
- }
- System.out.println("Number of symbols: " + numSymbols);
- System.out.println("Number of wheels: " + numWheels);
- List<Consumer<Deque<Integer>>> conditionCheckers = new ArrayList<>();
- AtomicInteger numThreeOfAKind = new AtomicInteger(0);
- Consumer<Deque<Integer>> threeOfAKindChecker = (values) -> {
- boolean isThreeOfAKind = values.stream()
- .collect(Collectors.groupingBy(k -> k, counting())).entrySet().stream()
- .anyMatch(e -> e.getValue() == 3);
- if (isThreeOfAKind) {
- numThreeOfAKind.incrementAndGet();
- System.out.print("<3oaK> ");
- }
- };
- conditionCheckers.add(threeOfAKindChecker);
- printValues(numWheels, numSymbols, new LinkedList<>(), conditionCheckers);
- long totalPayouts = numThreeOfAKind.get() * threeOfAKindPayout + numSymbols * fourOfAKindPayout;
- float averagePayout = totalPayouts / (float) totalCombinations;
- System.out.println("Total combinations: " + totalCombinations);
- System.out.println("Total three-of-a-kind: " + numThreeOfAKind.get());
- System.out.println("Total four-of-a-kind: " + numSymbols);
- System.out.println("Average payout: " + averagePayout);
- }
- private static void printValues(int wheelsRemaining, int numSymbols, Deque<Integer> values,
- List<Consumer<Deque<Integer>>> conditionCheckers) {
- if (wheelsRemaining == 0) {
- values.stream().forEach(v -> System.out.print(v + " "));
- conditionCheckers.stream().forEach(c -> c.accept(values));
- System.out.println("");
- return;
- }
- for (int i = 0; i < numSymbols; ++i) {
- values.push(i + 1);
- printValues(wheelsRemaining - 1, numSymbols, values, conditionCheckers);
- values.pop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment