Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- public class Playground {
- public static void main(String[] args) {
- int simulations = 1000000;
- Map<Integer, Integer> hitsPerPull = new HashMap<>();
- for (int i=0; i<simulations; i++) {
- int pullNumber = drawUntilHit();
- int currentHitsCount = hitsPerPull.getOrDefault(pullNumber, 0);
- hitsPerPull.put(pullNumber, currentHitsCount + 1);
- }
- hitsPerPull.forEach((key, value) ->
- System.out.printf("%d, %f\n", key, (double)value/simulations));
- }
- private static int drawUntilHit() {
- double hitProbability = 0.02;
- int pity1 = 0;
- int pity2 = 0;
- int pullNumber = 1;
- while (true) {
- if (Math.random() < hitProbability) {
- return pullNumber;
- }
- int pityIncrement = resolvePityIncrementForPull(pullNumber);
- boolean shouldIncreaseFirstPity = Math.random() > 0.5;
- if (shouldIncreaseFirstPity) {
- pity1 += pityIncrement;
- } else {
- pity2 += pityIncrement;
- }
- if (pity1 >= 37 || pity2 >= 37) {
- return pullNumber;
- }
- pullNumber += 1;
- }
- }
- private static int resolvePityIncrementForPull(int pullNumber) {
- if (pullNumber < 60) {
- return 1;
- } else if (pullNumber == 60) {
- return 5;
- } else {
- return 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment