• Source
    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 DieRunner {
    9. class Die{
    10. int top=1;
    11. int left=3;
    12. int right=4;
    13. int back=5;
    14. int forword=2;
    15. int rev=6;
    16. public int forword(){
    17. int x=top;
    18. top=back;
    19. back=rev;
    20. rev=forword;
    21. forword=x;
    22. return top;
    23. }
    24. public int left(){
    25. int x=top;
    26. top=right;
    27. right=rev;
    28. rev=left;
    29. left=x;
    30. return top;
    31. }
    32. public int right(){
    33. int x=top;
    34. top=left;
    35. left=rev;
    36. rev=right;
    37. right=x;
    38. return top;
    39. }
    40. public int back(){
    41. int x=top;
    42. top=forword;
    43. forword=rev;
    44. rev=back;
    45. back=x;
    46. return top;
    47. }
    48. }
    49. void test(String movement,String answer){
    50. Die die=new Die();
    51. StringBuilder ans=new StringBuilder();
    52. ans.append(1);
    53. for(char x:movement.toCharArray()){
    54. switch(x){
    55. case 'N':
    56. ans.append(die.forword());break;
    57. case 'W':
    58. ans.append(die.left());break;
    59. case 'E':
    60. ans.append(die.right());break;
    61. case 'S':
    62. ans.append(die.back());break;
    63. }
    64. }
    65. System.out.println(ans.toString()+":"+answer+"="+(ans.toString().equals(answer)));
    66. }
    67. private void run(){
    68. /*0*/ test( "NNESWWS", "15635624" );
    69. /*1*/ test( "EEEE", "13641" );
    70. /*2*/ test( "WWWW", "14631" );
    71. /*3*/ test( "SSSS", "12651" );
    72. /*4*/ test( "NNNN", "15621" );
    73. /*5*/ test( "EENN", "13651" );
    74. /*6*/ test( "WWNN", "14651" );
    75. /*7*/ test( "SSNN", "12621" );
    76. /*8*/ test( "NENNN", "153641" );
    77. /*9*/ test( "NWNNN", "154631" );
    78. /*10*/ test( "SWWWSNEEEN", "12453635421" );
    79. /*11*/ test( "SENWSWSNSWE", "123123656545" );
    80. /*12*/ test( "SSSWNNNE", "126546315" );
    81. /*13*/ test( "SWNWSSSWWE", "12415423646" );
    82. /*14*/ test( "ENNWWS", "1354135" );
    83. /*15*/ test( "ESWNNW", "1321365" );
    84. /*16*/ test( "NWSSE", "154135" );
    85. /*17*/ test( "SWNWEWSEEN", "12415154135" );
    86. /*18*/ test( "EWNWEEEEWN", "13154532426" );
    87. /*19*/ test( "WNEWEWWWSNW", "145151562421" );
    88. /*20*/ test( "NNEE", "15631" );
    89. /*21*/ test( "EEEEWNWSW", "1364145642" );
    90. /*22*/ test( "SENNWWES", "123142321" );
    91. /*23*/ test( "SWWWSNSNESWW", "1245363635631" );
    92. /*24*/ test( "WESSENSE", "141263231" );
    93. /*25*/ test( "SWNSSESESSS", "124146231562" );
    94. /*26*/ test( "ENS", "1353" );
    95. /*27*/ test( "WNN", "1453" );
    96. /*28*/ test( "SSEENEEEN", "1263124536" );
    97. /*29*/ test( "NWSNNNW", "15414632" );
    98. /*30*/ test( "ESSSSSWW", "132453215" );
    99. /*31*/ test( "ESE", "1326" );
    100. /*32*/ test( "SNWNWWNSSSS", "121456232453" );
    101. /*33*/ test( "SWEESEN", "12423653" );
    102. /*34*/ test( "NEEWNSSWWW", "15323631562" );
    103. /*35*/ test( "WSEW", "14212" );
    104. /*36*/ test( "SWSNNNSNWE", "12464131353" );
    105. /*37*/ test( "ENWEWSEEW", "1351513545" );
    106. /*38*/ test( "WSEWN", "142124" );
    107. /*39*/ test( "EWNEESEWE", "1315321414" );
    108. /*40*/ test( "NESEEN", "1531263" );
    109. /*41*/ test( "WSW", "1426" );
    110. /*42*/ test( "ENEWE", "135656" );
    111. }
    112. /**
    113. * @param args
    114. */
    115. public static void main(String[] args) {
    116. new DieRunner().run();
    117. }
    118.  
    119. }