From 922c9913858ac4489eaa95e24fe27d95990958d5 Mon Sep 17 00:00:00 2001 From: Eoghan Conlon Date: Mon, 9 Dec 2024 12:03:42 +0000 Subject: [PATCH] Day03 p1 Fix. Changing sample function to match what the input function uses Signed-off-by: Eoghan Conlon --- src/Day03.java | 71 +++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/Day03.java b/src/Day03.java index 89db8e9..b20a2e4 100644 --- a/src/Day03.java +++ b/src/Day03.java @@ -11,44 +11,45 @@ public class Day03 extends Input { public int part1_sample(){ int rValue = 0; - String input = this.input.getSample_input().getFirst(); - String pattern = "mul("; - String num1_s = ""; - String num2_s = ""; - String nums = "0123456789"; - int num = 1; - int pattern_cnt = 0; - for(int i = 0; i < input.length(); i += 1){ - if(pattern_cnt != pattern.length()) { - if (input.charAt(i) == pattern.charAt(pattern_cnt)) { - pattern_cnt += 1; - } else { - pattern_cnt = 0; - } - } else { - if(nums.contains(Character.toString(input.charAt(i)))){ - if(num == 1){ - num1_s += input.charAt(i); - } else if (num == 2) { - num2_s += input.charAt(i); + for(String input : this.input.getSample_input()) { + String pattern = "mul("; + String num1_s = ""; + String num2_s = ""; + String nums = "0123456789"; + int num = 1; + int pattern_cnt = 0; + for (int i = 0; i < input.length(); i += 1) { + if (pattern_cnt != pattern.length()) { + if (input.charAt(i) == pattern.charAt(pattern_cnt)) { + pattern_cnt += 1; } else { - System.err.println("Something went wrong"); + pattern_cnt = 0; } - } else if (input.charAt(i) == ',' && num == 1){ - num += 1; - } else if (input.charAt(i) == ')' && num == 2){ - int num1 = Integer.parseInt(num1_s); - int num2 = Integer.parseInt(num2_s); - rValue += (num1 * num2); - num = 1; - pattern_cnt = 0; - num1_s = ""; - num2_s = ""; } else { - num = 1; - pattern_cnt = 0; - num1_s = ""; - num2_s = ""; + if (nums.contains(Character.toString(input.charAt(i)))) { + if (num == 1) { + num1_s += input.charAt(i); + } else if (num == 2) { + num2_s += input.charAt(i); + } else { + System.err.println("Something went wrong"); + } + } else if (input.charAt(i) == ',' && num == 1) { + num += 1; + } else if (input.charAt(i) == ')' && num == 2) { + int num1 = Integer.parseInt(num1_s); + int num2 = Integer.parseInt(num2_s); + rValue += (num1 * num2); + num = 1; + pattern_cnt = 0; + num1_s = ""; + num2_s = ""; + } else { + num = 1; + pattern_cnt = 0; + num1_s = ""; + num2_s = ""; + } } } }