Advertisement
Guest User

Day 3

a guest
Dec 3rd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class Day3part1
  5. {
  6. public static void main(String args[]) throws Exception
  7. {
  8. File file = new File("PATH TO THE TXT");
  9.  
  10. Scanner scanner = new Scanner(file);
  11.  
  12. String string1 = scanner.nextLine();
  13. String string2 = scanner.nextLine();
  14.  
  15. ArrayList<String> list1 = new ArrayList<String>(Arrays.asList(string1.split(",")));
  16. ArrayList<String> list2 = new ArrayList<String>(Arrays.asList(string2.split(",")));
  17.  
  18. scanner.close();
  19.  
  20. Wire one = new Wire(0, 0);
  21. Wire two = new Wire(0, 0);
  22.  
  23. for (int j = 0; j < list2.size() / 10; j++)
  24. {
  25.  
  26. for (int i = 0; i < list1.size() / 10; i++) {
  27. if (one.xCoord == two.xCoord && one.yCoord == two.yCoord)
  28. {
  29. System.out.println("INTERSECTION AT (" + one.xCoord + ", " + one.yCoord + ")");
  30. }
  31.  
  32. if (list1.get(i).contains("U0") || list1.get(i).contains("R0") || list1.get(i).contains("D0")
  33. || list1.get(i).contains("L0"))
  34. {
  35. continue;
  36. }
  37.  
  38. if (list1.get(i).contains("U"))
  39. {
  40. one.xCoord += 1;
  41. list1.set(i, "U" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
  42. i--;
  43. }
  44.  
  45. else if (list1.get(i).contains("R"))
  46. {
  47. one.yCoord += 1;
  48. list1.set(i, "R" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
  49. i--;
  50. }
  51.  
  52. else if (list1.get(i).contains("D"))
  53. {
  54. one.xCoord -= 1;
  55. list1.set(i, "D" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
  56. i--;
  57. }
  58.  
  59. else if (list1.get(i).contains("L"))
  60. {
  61. one.yCoord -= 1;
  62. list1.set(i, "L" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
  63. i--;
  64. }
  65. }
  66.  
  67. if (list2.get(j).contains("U0") || list2.get(j).contains("R0") || list2.get(j).contains("D0")
  68. || list2.get(j).contains("L0"))
  69. {
  70. continue;
  71. }
  72.  
  73. if (list2.get(j).contains("U"))
  74. {
  75. two.xCoord += 1;
  76. list2.set(j, "U" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
  77. j--;
  78. }
  79.  
  80. if (list2.get(j).contains("R"))
  81. {
  82. two.yCoord += 1;
  83. list2.set(j, "R" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
  84. j--;
  85. }
  86.  
  87. if (list2.get(j).contains("D"))
  88. {
  89. two.xCoord -= 1;
  90. list2.set(j, "D" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
  91. j--;
  92. }
  93.  
  94. if (list2.get(j).contains("L"))
  95. {
  96. two.yCoord -= 1;
  97. list2.set(j, "L" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
  98. j--;
  99. }
  100. }
  101. }
  102. }
  103.  
  104.  
  105.  
  106.  
  107. OTHER FILE:
  108.  
  109. public class Wire
  110. {
  111. int xCoord;
  112. int yCoord;
  113.  
  114. Wire(int xCoord, int yCoord)
  115. {
  116. this.xCoord = xCoord;
  117. this.yCoord = yCoord;
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement