solved 1
This commit is contained in:
@@ -1,5 +1,49 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Problem1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
ArrayList<String> allLines = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader("inputs/inputProblem1.txt"))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
allLines.add(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Call solve and print result
|
||||
System.out.println(solve(allLines));
|
||||
}
|
||||
|
||||
public static int solve(ArrayList<String> allLines) {
|
||||
int dial = 50;
|
||||
|
||||
int total = 0;
|
||||
|
||||
for (String line : allLines) {
|
||||
int value = Integer.parseInt(line.substring(1));
|
||||
if (line.charAt(0)=='L'){
|
||||
System.out.println("Turned Left: " + value);
|
||||
dial -= value;
|
||||
} else {
|
||||
System.out.println("Turned Right: " + value);
|
||||
dial += value;
|
||||
}
|
||||
|
||||
int num = (dial % 100 + 100) % 100; // Ensure num is between 0-99
|
||||
System.out.println("Current Dial Position: " + num);
|
||||
|
||||
if (num == 0) {
|
||||
total++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
4543
inputs/inputProblem1.txt
Normal file
4543
inputs/inputProblem1.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user