aoc/day02.java

49 lines
1003 B
Java
Raw Normal View History

2021-12-02 23:36:12 -05:00
// so how do we parse this file?
// .split("regex here...")
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class day02 {
public static void main(String[] args) throws IOException {
int posHorizontal = 0;
int posDepth = 0;
int finalAns = 0; // posHorizontal * posDepth
String line;
String direction;
int movement;
BufferedReader in = new BufferedReader(new FileReader("day02-input.txt"));
line = in.readLine();
while (line != null) {
String[] lineProcess = line.split(" ");
direction = lineProcess[0];
movement = Integer.valueOf(lineProcess[1]).intValue();
if (direction.compareTo("forward") == 0) {
posHorizontal += movement;
}
else if (direction.compareTo("up") == 0) {
posDepth -= movement;
}
else if (direction.compareTo("down") == 0) {
posDepth += movement;
}
line = in.readLine();
}
in.close();
finalAns = posHorizontal * posDepth;
System.out.println(finalAns);
}
}