-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartOne.java
34 lines (30 loc) · 928 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
34
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
* --- Day 1: Trebuchet?! ---
*
*
* https://adventofcode.com/2023/day/1
**/
public class PartOne {
public static void main(String[] args) throws Exception {
int total = 0;
String firstInt = "";
String lastInt = "";
try {
Scanner scanner = new Scanner(new File("./src/input.txt"));
while (scanner.hasNextLine()) {
String input = scanner.nextLine();
input = input.replaceAll("[^0-9]", "");
firstInt = input.substring(0, 1);
lastInt = input.substring(input.length() - 1);
total += Integer.parseInt(firstInt + lastInt);
}
scanner.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
System.out.println(total);
}
}