Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.nio.file.Files;
  3. import java.nio.file.Paths;
  4. import java.util.ArrayList;
  5. //import java.util.Hashtable;
  6.  
  7. public class PresentDelivery {
  8. static int x = 0;
  9. static int y = 0;
  10. static int xr = 0;
  11. static int yr = 0;
  12. static boolean repeat = false;
  13. static int housesVisited = 0;
  14. static boolean robot = false;
  15. static ArrayList<Integer> XValues = new ArrayList<Integer>();
  16. static ArrayList<Integer> YValues = new ArrayList<Integer>();
  17. public static void main(String[] args) throws IOException {
  18. // TODO Auto-generated method stub
  19. //housesVisited++;
  20. for(String line : Files.readAllLines(Paths.get("C:/Users/Gregorio21/Desktop/Advent.txt"))){
  21. for(char chars : line.toCharArray()){
  22. if(robot){
  23. robot = false;
  24. if(chars == '^'){
  25. yr++;
  26.  
  27. }
  28. else if(chars == 'v'){
  29. yr--;
  30.  
  31. }
  32. else if(chars == '>'){
  33. xr++;
  34.  
  35. }
  36. else if(chars == '<'){
  37. xr--;
  38.  
  39. }
  40. for(int i = 0; i < XValues.size(); i++){
  41. if(XValues.get(i) == xr && YValues.get(i) == yr){
  42. repeat = true;
  43. }
  44. }
  45. if(!repeat){
  46. housesVisited ++;
  47. }
  48. XValues.add(xr);
  49. YValues.add(yr);
  50. repeat = false;
  51. }
  52. else if(!robot){
  53. robot = true;
  54. if(chars == '^'){
  55. y++;
  56.  
  57. }
  58. else if(chars == 'v'){
  59. y--;
  60.  
  61. }
  62. else if(chars == '>'){
  63. x++;
  64.  
  65. }
  66. else if(chars == '<'){
  67. x--;
  68.  
  69. }
  70. for(int i = 0; i < XValues.size(); i++){
  71. if(XValues.get(i) == x && YValues.get(i) == y){
  72. repeat = true;
  73. }
  74. }
  75. if(!repeat){
  76. housesVisited ++;
  77. }
  78. XValues.add(x);
  79. YValues.add(y);
  80. repeat = false;
  81. }
  82. }
  83. }
  84. System.out.println(housesVisited);
  85. }
  86. /*public static void housesVisited(int xMove, int yMove){
  87. if(xMove != 0){
  88. if(xMove == -previousx && !vertical){
  89.  
  90. }
  91. else{
  92. housesVisited++;
  93. }
  94. previousx = xMove;
  95. horizontal = true;
  96. vertical = false;
  97. }
  98. else if(yMove != 0){
  99. if(yMove == -previousy && !horizontal){
  100.  
  101. }
  102. else{
  103. housesVisited++;
  104. }
  105. previousy = yMove;
  106. vertical = true;
  107. horizontal = false;
  108. }
  109. }*/
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement