Day 02 p2 complete

Signed-off-by: Eoghan Conlon <git@eoghanconlon.ie>
This commit is contained in:
Eoghan Conlon 2024-12-09 12:58:11 +00:00
parent d544a7b5c7
commit b7eff97777

View file

@ -120,25 +120,17 @@ public class Day02 extends Input{
} else { } else {
safe -= 1; safe -= 1;
int[] reading_cut = new int[readings.length - 1]; int[] reading_cut = new int[readings.length - 1];
for(int i = 0, j = 0; i < readings.length; i += 1){ while(danger >= 0 && oldSafeRead == safeReadings){
if(i != danger){ for(int a = 0, b = 0; a < readings.length; a += 1){
reading_cut[j] = readings[i]; if(a != danger){
j += 1; reading_cut[b] = readings[a];
} b += 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;
} }
} }
if(safe_p2(reading_cut) == -1){ if(safe_p2(reading_cut) == -1){
safeReadings += 1; safeReadings += 1;
} else { } else {
safe -= 1; danger -= 1;
} }
} }
} }