-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay1Part1.java
More file actions
30 lines (22 loc) · 908 Bytes
/
Copy pathDay1Part1.java
File metadata and controls
30 lines (22 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.File;
import java.io.FileNotFoundException;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Day1Part1 {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("day1-input.txt"));
PriorityQueue<Integer> firstList = new PriorityQueue<>();
PriorityQueue<Integer> secondList = new PriorityQueue<>();
while (input.hasNextLine()) {
String[] numbers = input.nextLine().split(" ");
firstList.add(Integer.parseInt(numbers[0]));
secondList.add(Integer.parseInt(numbers[1]));
}
assert firstList.size() == secondList.size();
int totalDistance = 0;
while (!firstList.isEmpty()) {
totalDistance += Math.abs(firstList.poll() - secondList.poll());
}
System.out.println(totalDistance);
}
}