fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<Boolean> deck = new ArrayList<Boolean>();
  13. int hits = 9;
  14. int size = 45;
  15.  
  16. for (int i = 1; i <= size; ++i) {
  17. if (i <= hits) {
  18. deck.add(true);
  19. }
  20. else {
  21. deck.add(false);
  22. }
  23. }
  24.  
  25. int iterations = 1000000;
  26. int successes = 0;
  27. int failures = 0;
  28.  
  29. int draws = 5;
  30.  
  31. for (int i = 1; i <= iterations; ++i) {
  32. if (findHitWithMull(deck, draws)) {
  33. successes++;
  34. }
  35. else {
  36. failures++;
  37. }
  38. }
  39. System.out.println("SUCCEEDS " + ((float)successes/(float)iterations)*100.0 + "%");
  40. }
  41.  
  42. private static boolean findHitWithMull(List<Boolean> deck, int draws) {
  43. return findHit(deck, draws) ? true : findHit(deck, draws);
  44. }
  45.  
  46. private static boolean findHit(List<Boolean> deck, int draws) {
  47. Collections.shuffle(deck);
  48. for (int i = 0; i < draws; ++i) {
  49. if (deck.get(i)) {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. }
Success #stdin #stdout 0.87s 4386816KB
stdin
Standard input is empty
stdout
SUCCEEDS 90.4753029346466%