1
0
Fork 0

init, day 1

This commit is contained in:
Justin Parsell 2021-12-01 01:38:01 -05:00
parent 97c4931e01
commit cb49e2b00d
3 changed files with 2044 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vscode

View File

@ -0,0 +1,41 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.json.JSONArray;
import org.json.JSONTokener;
class increaseCounter{
public static void main(String[] args){
File input = new File("input.json");
try{
InputStream fileIn = new FileInputStream(input);
JSONTokener inputJson = new JSONTokener(fileIn);
JSONArray values = (JSONArray)inputJson.nextValue();
//System.out.println(inputArray.toString());
// Get the amount of times it increases
int increaseCount = 0;
for(int i = 1; i < values.length(); i++)
if(values.getInt(i-1) < values.getInt(i))
increaseCount++;
System.out.println(increaseCount);
// Get the amount of times it increase by three-measure sliding increments
int increaseCount3 = 0;
for(int i = 3; i < values.length(); i++){
int winA = values.getInt(i - 3) + values.getInt(i - 2) + values.getInt(i - 1);
int winB = values.getInt(i - 2) + values.getInt(i - 1) + values.getInt(i);
if(winA < winB)
increaseCount3++;
}
System.out.println(increaseCount3);
} catch(FileNotFoundException e){
e.printStackTrace();
}
}
}

2002
Day 1/Java/input.json Normal file

File diff suppressed because it is too large Load Diff