justin day 2
This commit is contained in:
parent
6e7edd18a6
commit
3cac60d542
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
Loading…
Reference in New Issue