From d5d903aa1055681c0f4b114b04075d21ab0b78c0 Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Tue, 2 Dec 2025 22:21:30 -0600 Subject: [PATCH] Fixed --- Problem1b.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Problem1b.java diff --git a/Problem1b.java b/Problem1b.java new file mode 100644 index 0000000..57f2943 --- /dev/null +++ b/Problem1b.java @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; + +public class Problem1b { + + public static void main(String[] args) { + ArrayList 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 allLines) { + int dial = 50; // starting position + int total = 0; + + for (String line : allLines) { + int value = Integer.parseInt(line.substring(1)); + int direction = (line.charAt(0) == 'L') ? -1 : 1; + + // Step through each click to count zeros correctly + for (int step = 0; step < value; step++) { + dial = (dial + direction + 100) % 100; // wrap around 0-99 + if (dial == 0) { + total++; + } + } + + System.out.println("Current Dial Position: " + dial + " || Total: " + total); + } + + return total; + } +} \ No newline at end of file