aoc/day01.java

51 lines
1.4 KiB
Java
Raw Normal View History

2021-12-02 23:36:12 -05:00
// In around 20 minutes
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class day01 {
public static void main(String[] args) throws IOException {
int hasIncreasedCounter = 0;
int lineCounter = 1;
int firstnum = 0;
int nextnum = 0;
String line; // convert to int or something
BufferedReader in = new BufferedReader(new FileReader("day01-input.txt"));
line = in.readLine();
while (line != null) {
if (lineCounter == 1) { // first line, no firstnum, set
firstnum = Integer.valueOf(line).intValue();
System.out.println("First entry " + firstnum);
}
else { // continue, as usual
nextnum = Integer.valueOf(line).intValue();
System.out.println("Comparing " + firstnum + " and " + nextnum);
if (nextnum > firstnum) {
System.out.println("Yes!");
hasIncreasedCounter++;
}
else {
System.out.println("Not bigger");
}
firstnum = nextnum; // swap to continue
}
lineCounter++;
// continue
line = in.readLine();
}
in.close(); // bye
System.out.println("Final is " + hasIncreasedCounter);
}
}