Fix. Changing sample function to match what the input function uses

Signed-off-by: Eoghan Conlon <git@eoghanconlon.ie>
This commit is contained in:
Eoghan Conlon 2024-12-09 12:03:42 +00:00
parent 44c6eb27e5
commit 28752ace22

View file

@ -11,32 +11,32 @@ public class Day03 extends Input {
public int part1_sample(){ public int part1_sample(){
int rValue = 0; int rValue = 0;
String input = this.input.getSample_input().getFirst(); for(String input : this.input.getSample_input()) {
String pattern = "mul("; String pattern = "mul(";
String num1_s = ""; String num1_s = "";
String num2_s = ""; String num2_s = "";
String nums = "0123456789"; String nums = "0123456789";
int num = 1; int num = 1;
int pattern_cnt = 0; int pattern_cnt = 0;
for(int i = 0; i < input.length(); i += 1){ for (int i = 0; i < input.length(); i += 1) {
if(pattern_cnt != pattern.length()) { if (pattern_cnt != pattern.length()) {
if (input.charAt(i) == pattern.charAt(pattern_cnt)) { if (input.charAt(i) == pattern.charAt(pattern_cnt)) {
pattern_cnt += 1; pattern_cnt += 1;
} else { } else {
pattern_cnt = 0; pattern_cnt = 0;
} }
} else { } else {
if(nums.contains(Character.toString(input.charAt(i)))){ if (nums.contains(Character.toString(input.charAt(i)))) {
if(num == 1){ if (num == 1) {
num1_s += input.charAt(i); num1_s += input.charAt(i);
} else if (num == 2) { } else if (num == 2) {
num2_s += input.charAt(i); num2_s += input.charAt(i);
} else { } else {
System.err.println("Something went wrong"); System.err.println("Something went wrong");
} }
} else if (input.charAt(i) == ',' && num == 1){ } else if (input.charAt(i) == ',' && num == 1) {
num += 1; num += 1;
} else if (input.charAt(i) == ')' && num == 2){ } else if (input.charAt(i) == ')' && num == 2) {
int num1 = Integer.parseInt(num1_s); int num1 = Integer.parseInt(num1_s);
int num2 = Integer.parseInt(num2_s); int num2 = Integer.parseInt(num2_s);
rValue += (num1 * num2); rValue += (num1 * num2);
@ -52,6 +52,7 @@ public class Day03 extends Input {
} }
} }
} }
}
return rValue; return rValue;
} }