### Problem 84

Before solving this problem
I thought lost of time. because. It request to me that I had to make monopoly rules and playing it to make statistic.

Anyway I made up~ never give up~!

What I learned from this problem is that statistics are very strong~!!!!!!

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232``` ```package euler.numberFrom71; import java.util.Arrays; import java.util.Collections; import java.util.Random; public class number84 { static int visitCount [] = new int[40]; static int currentPosition =0; static int money[] = new int [16]; static int moneyPosition = 0; static String chance[] = new String [16]; static int chancePosition = 0; static int []log = new int[40]; static String [] map = { "GO", "A1","CC1","A2","T1","R1","B1","CH1","B2","B3", //0 ~9 "JAIL", "C1", "U1", "C2", "C3", "R2", "D1", "CC2","D2","D3", // 10-19 "FP", "E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3", // 20- 29 "G2J", "G1","G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2" //30-39 }; public static void main(String args[]) throws InterruptedException{ settingMoneyAndChange(); Random ran = new Random(); for (int i = 0; i < 10000000; i++) { int count =0; boolean isCountinue = true; while (isCountinue) { DiceResult result = goDice(); // 더블체크 if(result .isDouble){ isCountinue = true; if(count == 2){ goToJail(); break; } count++; }else{ isCountinue = false; } int tempTotal = currentPosition+ result.total; if(tempTotal > map.length -1){ currentPosition =tempTotal - map.length; }else{ currentPosition = tempTotal; } // 점령한다 // 더블이여도 감옥가면 그만 if(!goToPosition(currentPosition)){ break; } } //System.out.println(Arrays.toString(visitCount)); Arrays.fill(log, 0); log[currentPosition] =9; //System.out.println(Arrays.toString(log)); } int [] temp = visitCount.clone(); Arrays.sort(temp); for (int i = temp.length-1; i > temp.length-4; i--) { for (int j = 0; j < visitCount.length; j++) { if(visitCount[j] == temp[i]){ System.out.println(map[j]); break; } } } } /** * 점령한다 * @param currentPosition2 */ private static boolean goToPosition(int destP) { if(map[destP].contains("CC")){ doPublic(destP); }else if(map[destP].contains("CH")){ doChance(destP); }else if(map[destP].contains("G2J")){ goToJail(); return false; }else{ visitCount[destP]++; } return true; } private static void doChance(int destP) { //System.out.println("chance " + chance[chancePosition]); if(chance[chancePosition] == null){ visitCount[destP]++; }else if(chance[chancePosition] .equals("")){ visitCount[destP]++; }else if(chance[chancePosition] .contains("N_")){ findNextPosition(chance[chancePosition]); visitCount[currentPosition]++; }else if(chance[chancePosition] .equals("B3")){ currentPosition = currentPosition-3; visitCount[currentPosition]++; }else{ findPosition(chance[chancePosition]); visitCount[currentPosition]++; } if(chancePosition == chance.length-1){ chancePosition =0; }else{ chancePosition++; } } private static void findNextPosition(String string) { String a = string.substring(2); for (int i = currentPosition; i < map.length; i++) { if(map[i].startsWith(a)){ currentPosition =i; return ; } } for (int i = 0; i < currentPosition; i++) { if(map[i].startsWith(a)){ currentPosition =i; return ; } } } private static void findPosition(String string) { for (int i = 0; i < map.length; i++) { if(string.equals(map[i])){ currentPosition = i; break; } } } private static void doPublic(int destP) { //System.out.println("doPublic " + money[moneyPosition]); if(money[moneyPosition] != -1){ currentPosition = money[moneyPosition]; visitCount[currentPosition]++; }else{ visitCount[destP]++; } if(moneyPosition == money.length-1){ moneyPosition =0; }else{ moneyPosition++; } } /** * 초기화 */ private static void settingMoneyAndChange() { Arrays.fill(money, -1); money[0] = 0; money[1] = 10; Arrays.fill(chance, null); chance[0] = "GO"; chance[1] = "JAIL"; chance[2] = "C1"; chance[3] = "E3"; chance[4] = "H2"; chance[5] = "R1"; chance[6] = "N_R"; chance[7] = "N_R"; chance[8] = "N_U"; chance[9] = "B3"; } private static void goToJail() { //System.out.println("감옥"); currentPosition = 10; visitCount[10]++; } public static DiceResult goDice(){ Random ran = new Random(); DiceResult result = new DiceResult(); int a=0; int b=0; int total =0; a= ran.nextInt(4)+1; b= ran.nextInt(4)+1; //System.out.println("주사위 : " + a +" , "+ b); if(a == b){ result.isDouble = true; //System.out.println("더블"); } total = a+b; result.total = total; return result; } } class DiceResult{ boolean isDouble = false; int total = 0; } ```