fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.concurrent.ThreadLocalRandom;
  7.  
  8. class Ideone {
  9. public static void main(String[] args) {
  10. int ok = 0;
  11. int target = 1100; //цель
  12.  
  13. for(int k = 0; k < 100; k++) {
  14. int balance = 1000; //текущий баланс
  15. int i = 0;
  16. int reward = 1; // начальная ставка
  17. while (balance > 0 && balance <= target && reward <= balance) {
  18. i++;
  19. int rnd = randomRange(1, 99);
  20. if (rnd >= 51) {
  21. balance -= reward;
  22. reward *= 2;
  23. } else if (rnd <= 49) {
  24. balance += reward;
  25. reward = 1;
  26. }
  27.  
  28. }
  29. if(balance >= target) {
  30. ok++;
  31. }
  32. }
  33. System.out.print("chance: " + ok);
  34. }
  35.  
  36. public static int randomRange(int min, int max) {
  37. return ThreadLocalRandom.current().nextInt(min, max + 1);
  38. }
  39. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
chance: 91