Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- class Day3part1
- {
- public static void main(String args[]) throws Exception
- {
- File file = new File("PATH TO THE TXT");
- Scanner scanner = new Scanner(file);
- String string1 = scanner.nextLine();
- String string2 = scanner.nextLine();
- ArrayList<String> list1 = new ArrayList<String>(Arrays.asList(string1.split(",")));
- ArrayList<String> list2 = new ArrayList<String>(Arrays.asList(string2.split(",")));
- scanner.close();
- Wire one = new Wire(0, 0);
- Wire two = new Wire(0, 0);
- for (int j = 0; j < list2.size() / 10; j++)
- {
- for (int i = 0; i < list1.size() / 10; i++) {
- if (one.xCoord == two.xCoord && one.yCoord == two.yCoord)
- {
- System.out.println("INTERSECTION AT (" + one.xCoord + ", " + one.yCoord + ")");
- }
- if (list1.get(i).contains("U0") || list1.get(i).contains("R0") || list1.get(i).contains("D0")
- || list1.get(i).contains("L0"))
- {
- continue;
- }
- if (list1.get(i).contains("U"))
- {
- one.xCoord += 1;
- list1.set(i, "U" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
- i--;
- }
- else if (list1.get(i).contains("R"))
- {
- one.yCoord += 1;
- list1.set(i, "R" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
- i--;
- }
- else if (list1.get(i).contains("D"))
- {
- one.xCoord -= 1;
- list1.set(i, "D" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
- i--;
- }
- else if (list1.get(i).contains("L"))
- {
- one.yCoord -= 1;
- list1.set(i, "L" + Integer.toString(Integer.parseInt(list1.get(i).substring(1, list1.get(i).length())) - 1));
- i--;
- }
- }
- if (list2.get(j).contains("U0") || list2.get(j).contains("R0") || list2.get(j).contains("D0")
- || list2.get(j).contains("L0"))
- {
- continue;
- }
- if (list2.get(j).contains("U"))
- {
- two.xCoord += 1;
- list2.set(j, "U" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
- j--;
- }
- if (list2.get(j).contains("R"))
- {
- two.yCoord += 1;
- list2.set(j, "R" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
- j--;
- }
- if (list2.get(j).contains("D"))
- {
- two.xCoord -= 1;
- list2.set(j, "D" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
- j--;
- }
- if (list2.get(j).contains("L"))
- {
- two.yCoord -= 1;
- list2.set(j, "L" + Integer.toString(Integer.parseInt(list2.get(j).substring(1, list2.get(j).length())) - 1));
- j--;
- }
- }
- }
- }
- OTHER FILE:
- public class Wire
- {
- int xCoord;
- int yCoord;
- Wire(int xCoord, int yCoord)
- {
- this.xCoord = xCoord;
- this.yCoord = yCoord;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement