diff --git a/src/Day02.java b/src/Day02.java index 2556de3..3b2af2f 100644 --- a/src/Day02.java +++ b/src/Day02.java @@ -120,25 +120,17 @@ public class Day02 extends Input{ } else { safe -= 1; int[] reading_cut = new int[readings.length - 1]; - for(int i = 0, j = 0; i < readings.length; i += 1){ - if(i != danger){ - reading_cut[j] = readings[i]; - j += 1; - } - } - if(safe_p2(reading_cut) == -1){ - safeReadings += 1; - } else { - for(int i = 0, j = 0; i < readings.length; i += 1){ - if(i != danger - 1){ - reading_cut[j] = readings[i]; - j += 1; + while(danger >= 0 && oldSafeRead == safeReadings){ + for(int a = 0, b = 0; a < readings.length; a += 1){ + if(a != danger){ + reading_cut[b] = readings[a]; + b += 1; } } if(safe_p2(reading_cut) == -1){ safeReadings += 1; } else { - safe -= 1; + danger -= 1; } } }