fork download
  1. import java.util.Random;
  2.  
  3. class Thesis4 {
  4.  
  5. public static void main(String[] args) {
  6. // allocate objects only once
  7. Random rand = new Random();
  8.  
  9. int totalRTIncorrect = 0;
  10. int totalRTCorrect = 0;
  11. int totalCorrect = 0;
  12. int totalIncorrect = 0;
  13.  
  14. for (int j = 0; j < 10000; j++) {
  15. int correct = 0;
  16. int incorrect = 0;
  17. int incorrect2 = 0;
  18. int incorrect3 = 0;
  19. int time = 0;
  20.  
  21. while (true) {
  22. int pickedNumber = rand.nextInt(400);
  23.  
  24. // happens every time, no point to move into if
  25. time++;
  26.  
  27. if (pickedNumber < 108) {
  28. // [0..107] = 108 / 400
  29.  
  30. // no need to add up to 88, return at 87
  31. if (correct >= 87) {
  32. // no need to calculate after the while loop, can be done directly
  33. totalRTCorrect += time;
  34. totalCorrect++;
  35. break;
  36. }
  37. // sum must not change +3-1-1-1 = 0
  38. correct += 3;
  39. incorrect--;
  40. incorrect2--;
  41. incorrect3--;
  42.  
  43. // else means there is no way the number can be
  44. // between 0 and 107, no need to check
  45. } else if (pickedNumber < 208) {
  46. // [108..207] = 100 / 400
  47. if (incorrect >= 87) {
  48. totalRTIncorrect += time;
  49. totalIncorrect++;
  50. break;
  51. }
  52. correct--;
  53. incorrect += 3;
  54. incorrect2--;
  55. incorrect3--;
  56.  
  57. } else if (pickedNumber < 309) {
  58. // [208..308] = 101 / 400
  59. if (incorrect2 >= 87) {
  60. totalRTIncorrect += time;
  61. totalIncorrect++;
  62. break;
  63. }
  64. correct--;
  65. incorrect--;
  66. incorrect2 += 3;
  67. incorrect3--;
  68.  
  69. } else {
  70. // [309..399] = 91 / 400
  71. if (incorrect3 >= 87) {
  72. totalRTIncorrect += time;
  73. totalIncorrect++;
  74. break;
  75. }
  76. correct--;
  77. incorrect--;
  78. incorrect2--;
  79. incorrect3 += 3;
  80. }
  81. }
  82. }
  83. System.out.printf("Total Correct Responses: %d \nTotal Incorrect Responses: %d",
  84. totalCorrect, totalIncorrect);
  85. System.out.printf("\nTotal Correct RT's: %d \nTotal Incorrect RT's: %d\n", totalRTCorrect,
  86. totalRTIncorrect);
  87. }
  88. }
Success #stdin #stdout 0.61s 380416KB
stdin
Standard input is empty
stdout
Total Correct Responses: 6968 
Total Incorrect Responses: 3032
Total Correct RT's: 5818914 
Total Incorrect RT's: 2700423