1
0
Fork 0

justin day 2

This commit is contained in:
Justin Parsell 2021-12-02 21:27:00 -05:00
parent 6e7edd18a6
commit 3cac60d542
5 changed files with 1097 additions and 1 deletions

View File

@ -8,7 +8,7 @@ import org.json.JSONTokener; //requires external "org.json"
class increaseCounter{
public static void main(String[] args){
File input = new File("input.json");
File input = new File("Day 1/Justin/Java/input.json");
try{
// Get the file, into an inputstream, and give it to json tokenizer

1000
Day 2/Justin/Java/input.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class part1{
public static void main(String[] args){
File input = new File("Day 2/Justin/Java/input.txt");
try{
// Get the file, and start to read it
Scanner fileIn = new Scanner(input);
int depth = 0;
int movement = 0;
do{
String inputLine = fileIn.nextLine();
System.out.println(inputLine);
String[] operations = inputLine.split(" ");
switch(operations[0]){
case "forward":
movement += Integer.parseInt(operations[1]);
break;
case "up":
depth -= Integer.parseInt(operations[1]);
break;
case "down":
depth += Integer.parseInt(operations[1]);
break;
default:
break;
}
} while(fileIn.hasNextLine());
fileIn.close();
System.out.println(depth * movement);
} catch(FileNotFoundException e){
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,46 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class part2{
public static void main(String[] args){
File input = new File("Day 2/Justin/Java/input.txt");
try{
// Get the file, and start to read it
Scanner fileIn = new Scanner(input);
int depth = 0;
int movement = 0;
int aim = 0;
do{
String inputLine = fileIn.nextLine();
System.out.println(inputLine);
String[] operations = inputLine.split(" ");
switch(operations[0]){
case "forward":
movement += Integer.parseInt(operations[1]);
depth += aim * Integer.parseInt(operations[1]);
break;
case "up":
aim -= Integer.parseInt(operations[1]);
break;
case "down":
aim += Integer.parseInt(operations[1]);
break;
default:
break;
}
} while(fileIn.hasNextLine());
fileIn.close();
System.out.printf("Depth: %d | Movement: %d | Value: %d", depth, movement, (depth * movement));
} catch(FileNotFoundException e){
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2