-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartOne.java
33 lines (30 loc) · 993 Bytes
/
PartOne.java
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
31
32
33
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
/**
* --- Day 3: Mull It Over ---
*
*
* https://adventofcode.com/2024/day/3
**/
public class PartOne {
public static void main(String[] args) throws Exception {
Path path = Path.of("2024/days/03/src/input.txt");
long multiplications = 0;
Pattern pattern = Pattern.compile("mul\\((\\d+),(\\d+)\\)");
try (var lines = Files.lines(path)) {
for (String line : lines.toList()) {
var matcher = pattern.matcher(line);
while (matcher.find()) {
String[] numbers = {
matcher.group(1), matcher.group(2)
};
long a = Long.parseLong(numbers[0]);
long b = Long.parseLong(numbers[1]);
multiplications += a * b;
}
}
}
System.out.println(multiplications);
}
}