From 00df5604d4eb5ea621b443e46f520f66c313560f Mon Sep 17 00:00:00 2001 From: Flashk Date: Sun, 8 Dec 2024 10:22:09 +0100 Subject: [PATCH] refactor: refactor day 8 --- .../flashk/day08/ResonantCollinearity.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/adventofcode/flashk/day08/ResonantCollinearity.java b/src/main/java/com/adventofcode/flashk/day08/ResonantCollinearity.java index 91e3b13..b665ae3 100644 --- a/src/main/java/com/adventofcode/flashk/day08/ResonantCollinearity.java +++ b/src/main/java/com/adventofcode/flashk/day08/ResonantCollinearity.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; + import java.util.List; import java.util.Map; import java.util.Set; @@ -39,15 +40,16 @@ public ResonantCollinearity(char[][] input) { public int solve(boolean countHarmonics) { Set antinodeLocations = new HashSet<>(); - for(Character frequency : antennasPerFrequency.keySet()) { - List antennas = antennasPerFrequency.get(frequency); + for(Map.Entry> frequency : antennasPerFrequency.entrySet()) { + + List antennas = frequency.getValue(); - for(int i = 0; i < antennas.size(); i++) { - for(int j = 1; j < antennas.size(); j++) { + for (int i = 0; i < antennas.size(); i++) { + for (int j = 1; j < antennas.size(); j++) { Vector2 antenna1 = antennas.get(i); Vector2 antenna2 = antennas.get(j); - if(antenna1.equals(antenna2)) { + if (antenna1.equals(antenna2)) { continue; } @@ -81,5 +83,4 @@ private boolean isInbounds(Vector2 antinodePos) { return antinodePos.getY() >= 0 && antinodePos.getY() < rows && antinodePos.getX() >= 0 && antinodePos.getX() < cols; } - }