aoc_omni/java/2015/1/Problem.java
2023-12-19 14:15:50 -05:00

30 lines
723 B
Java

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Problem {
public static void main(String[] args) {
try {
char[] input = new String(Files.readAllBytes(Paths.get("../../../data/2015/1/input.txt"))).toCharArray();
int floor = 0;
for (int i = 0; i < input.length; i++) {
if (input[i] == '(') floor++;
else floor--;
}
System.out.println("Part 1: " + floor);
floor = 0;
int steps = 0;
for (int i = 0; i < input.length; i++) {
if (input[i] == '(') floor++;
else floor--;
steps++;
if (floor < 0) break;
}
System.out.println("Part 2: " + steps);
} catch (IOException ex) {
System.out.println(ex);
}
}
}