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.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. DialAPirate DialAPirateInst = new DialAPirate();
  15. DialAPirateInst.createDisks();
  16. System.out.println("pirateId: "+DialAPirateInst.getPirateDisplay());
  17. }
  18. }
  19. class DialAPirate {
  20. private int [][] years = { {1710, 1651, 1679, 1719, 1694, 1632, 1668, 1703, 1726, 1564, 1615, 1599, 1669, 1660, 1687},
  21. {1658, 1702, 1725, 1630, 1709, 1594, 1614, 1563, 1649, 1693, 1577, 1678, 1686, 1597, 1718},
  22. {1724, 1667, 1691, 1685, 1613, 1580, 1723, 1717, 1684, 1628, 1643, 1559, 1573, 1708, 1701},
  23. {1672, 1562, 1721, 1666, 1673, 1670, 1692, 1656, 1567, 1674, 1662, 1655, 1646, 1671, 1611},
  24. {1627, 1707, 1688, 1699, 1568, 1705, 1579, 1585, 1665, 1706, 1506, 1722, 1716, 1584, 1551},
  25. {1566, 1592, 1654, 1635, 1639, 1695, 1704, 1711, 1609, 1681, 1712, 1542, 1565, 1720, 1664},
  26. {1690, 1682, 1601, 1619, 1680, 1621, 1652, 1689, 1713, 1697, 1696, 1624, 1604, 1653, 1641}};
  27.  
  28. ArrayList<Integer> disk1 = new ArrayList<Integer>();
  29. ArrayList<Integer> disk2 = new ArrayList<Integer>();
  30. public void createDisks() {
  31. int i;
  32. for(i=1; i <=29; i = i +2 ){
  33. disk1.add(i);
  34. }
  35. for(i=2; i <=30; i = i +2 ){
  36. disk2.add(i);
  37. }
  38. }
  39. public String getPirateDisplay() {
  40. return Integer.toString(this.getPirateID());
  41. }
  42. private int[][] getMapping() {
  43. int[][] mapping = {
  44. // { 12 , 34 , 56 , 78 , 910 , 1112 , 1314 , 1516 , 1718 , 1920 , 2122 , 2324 , 2526 , 2728 , 2930 },
  45. { 130 , 32 , 54 , 76 , 98 , 1110 , 1312 , 1514 , 1716 , 1918 , 2120 , 2322 , 2524 , 2726 , 2928 },
  46. { 128 , 330 , 52 , 74 , 96 , 118 , 1310 , 1512 , 1714 , 1916 , 2118 , 2320 , 2522 , 2724 , 2926 },
  47. { 126 , 328 , 530 , 72 , 94 , 116 , 138 , 1510 , 1712 , 1914 , 2116 , 2318 , 2520 , 2722 , 2924 },
  48. { 124 , 326 , 528 , 730 , 92 , 114 , 136 , 158 , 1710 , 1912 , 2114 , 2316 , 2518 , 2720 , 2922 },
  49. { 122 , 324 , 526 , 728 , 930 , 112 , 134 , 156 , 178 , 1910 , 2112 , 2314 , 2516 , 2718 , 2920 },
  50. { 120 , 322 , 524 , 726 , 928 , 1130 , 132 , 154 , 176 , 198 , 2110 , 2312 , 2514 , 2716 , 2918 },
  51. { 118 , 320 , 522 , 724 , 926 , 1128 , 1330 , 152 , 174 , 196 , 218 , 2310 , 2512 , 2714 , 2916 },
  52. { 116 , 318 , 520 , 722 , 924 , 1126 , 1328 , 1530 , 172 , 194 , 216 , 238 , 2510 , 2712 , 2914 },
  53. { 114 , 316 , 518 , 720 , 922 , 1124 , 1326 , 1528 , 1730 , 192 , 214 , 236 , 258 , 2710 , 2912 },
  54. { 112 , 314 , 516 , 718 , 920 , 1122 , 1324 , 1526 , 1728 , 1930 , 212 , 234 , 256 , 278 , 2910 },
  55. { 110 , 312 , 514 , 716 , 918 , 1120 , 1322 , 1524 , 1726 , 1928 , 2130 , 232 , 254 , 276 , 298 },
  56. { 18 , 310 , 512 , 714 , 916 , 1118 , 1320 , 1522 , 1724 , 1926 , 2128 , 2330 , 252 , 274 , 296 },
  57. { 16 , 38 , 510 , 712 , 914 , 1116 , 1318 , 1520 , 1722 , 1924 , 2126 , 2328 , 2530 , 272 , 294 },
  58. { 14 , 36 , 58 , 710 , 912 , 1114 , 1316 , 1518 , 1720 , 1922 , 2124 , 2326 , 2528 , 2730 , 292 },
  59. { 34 , 56 , 78 , 910 , 1112 , 1314 , 1516 , 1718 , 1920 , 2122 , 2324 , 2526 , 2728 , 2930, 12 }
  60. };
  61. return mapping;
  62. }
  63.  
  64. private int getPirateID() {
  65.  
  66. String temp = Integer.toString(disk1.get(0)) + Integer.toString(disk2.get(0));
  67. int pirateID = Integer.parseInt(temp);
  68. System.out.println("temp:" + temp);
  69. int[][] mapping = this.getMapping();
  70. for(int i=0; i<mapping.length; i++) {
  71. //String[] sarr = Arrays.stream(mapping[i]).mapToObj(String::valueOf).toArray(String[]::new);
  72. //System.out.println("mapping["+Integer.toString(i)+"]: "+String.join(" - ", sarr));
  73. for (int j=0; j <mapping[i].length; j++) {
  74. if (mapping[i][j] == pirateID) {
  75. return i;
  76. }
  77. }
  78. }
  79. return -1; // not found
  80. }
  81. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
temp:12
pirateId: 14