Guest User

Untitled

a guest
May 22nd, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. public class Playground {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         int simulations = 1000000;
  9.         Map<Integer, Integer> hitsPerPull = new HashMap<>();
  10.  
  11.         for (int i=0; i<simulations; i++) {
  12.             int pullNumber = drawUntilHit();
  13.  
  14.             int currentHitsCount = hitsPerPull.getOrDefault(pullNumber, 0);
  15.             hitsPerPull.put(pullNumber, currentHitsCount + 1);
  16.         }
  17.  
  18.         hitsPerPull.forEach((key, value) ->
  19.                 System.out.printf("%d, %f\n", key, (double)value/simulations));
  20.     }
  21.  
  22.     private static int drawUntilHit() {
  23.         double hitProbability = 0.02;
  24.         int pity1 = 0;
  25.         int pity2 = 0;
  26.         int pullNumber = 1;
  27.  
  28.         while (true) {
  29.             if (Math.random() < hitProbability) {
  30.                 return pullNumber;
  31.             }
  32.  
  33.             int pityIncrement = resolvePityIncrementForPull(pullNumber);
  34.             boolean shouldIncreaseFirstPity = Math.random() > 0.5;
  35.             if (shouldIncreaseFirstPity) {
  36.                 pity1 += pityIncrement;
  37.             } else {
  38.                 pity2 += pityIncrement;
  39.             }
  40.  
  41.             if (pity1 >= 37 || pity2 >= 37) {
  42.                 return pullNumber;
  43.             }
  44.  
  45.             pullNumber += 1;
  46.         }
  47.     }
  48.  
  49.     private static int resolvePityIncrementForPull(int pullNumber) {
  50.         if (pullNumber < 60) {
  51.             return 1;
  52.         } else if (pullNumber == 60) {
  53.             return 5;
  54.         } else {
  55.             return 2;
  56.         }
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment