Skip to content

Commit d266f6f

Browse files
committed
Day 20 WIP
1 parent ce45828 commit d266f6f

File tree

8 files changed

+126
-5
lines changed

8 files changed

+126
-5
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.adventofcode.flashk.day20;
2+
3+
import org.apache.commons.lang3.tuple.Pair;
4+
5+
public class Broadcast extends MultiOutputModule{
6+
7+
@Override
8+
public void process() {
9+
if(!this.inputPulses.isEmpty()) {
10+
Pair<Module, String> inputPulse = this.inputPulses.poll();
11+
12+
// Send a pulse
13+
for(Module output : outputs) {
14+
output.addPulse(this, inputPulse.getRight());
15+
}
16+
17+
// Process pulse in order of sending
18+
for(Module output : outputs) {
19+
output.process();
20+
}
21+
}
22+
23+
24+
}
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.adventofcode.flashk.day20;
2+
3+
import org.apache.commons.lang3.tuple.ImmutablePair;
4+
import org.apache.commons.lang3.tuple.Pair;
5+
6+
public class Button extends SingleOutputModule {
7+
8+
@Override
9+
public void process() {
10+
if(!inputPulses.isEmpty()) {
11+
Pair<Module, String> inputPulse = this.inputPulses.poll();
12+
this.output.addPulse(this, inputPulse.getRight());
13+
this.output.process();
14+
}
15+
16+
}
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.adventofcode.flashk.day20;
2+
3+
import org.apache.commons.lang3.tuple.ImmutablePair;
4+
import org.apache.commons.lang3.tuple.Pair;
5+
6+
import java.sql.Array;
7+
import java.util.ArrayDeque;
8+
import java.util.ArrayList;
9+
import java.util.Deque;
10+
import java.util.List;
11+
12+
public abstract class Module {
13+
14+
public static final String LOW = "low";
15+
public static final String HIGH = "high";
16+
17+
protected Deque<Pair<Module,String>> inputPulses = new ArrayDeque<>();
18+
19+
public void addPulse(Module origin, String value) {
20+
this.inputPulses.add(ImmutablePair.of(origin, value));
21+
}
22+
23+
public abstract void addOutput(Module output);
24+
25+
public abstract void process();
26+
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.adventofcode.flashk.day20;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public abstract class MultiOutputModule extends Module {
7+
8+
protected List<Module> outputs = new ArrayList<>();
9+
10+
@Override
11+
public void addOutput(Module output) {
12+
this.outputs.add(output);
13+
}
14+
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.adventofcode.flashk.day20;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
public class PulsePropagation {
8+
9+
private Map<String,Object> modules = new HashMap<>();
10+
11+
public PulsePropagation(List<String> inputs) {
12+
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.adventofcode.flashk.day20;
2+
3+
public abstract class SingleOutputModule extends Module {
4+
5+
protected Module output;
6+
7+
@Override
8+
public void addOutput(Module output) {
9+
this.output = output;
10+
}
11+
12+
}

src/test/java/com/adventofcode/flashk/day20/Day20Test.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44

55
import org.junit.jupiter.api.BeforeAll;
6+
67
import org.junit.jupiter.api.Disabled;
78
import org.junit.jupiter.api.DisplayName;
89
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
@@ -19,9 +20,11 @@
1920
import com.adventofcode.flashk.common.test.utils.Timer;
2021
import com.adventofcode.flashk.common.test.utils.Input;
2122

23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
2225
@DisplayName(TestDisplayName.DAY_20)
2326
@TestMethodOrder(OrderAnnotation.class)
24-
@Disabled // TODO Remove comment when implemented
27+
@Disabled
2528
public class Day20Test extends PuzzleTest {
2629

2730
private final static String INPUT_FOLDER = TestFolder.DAY_20;
@@ -43,7 +46,9 @@ public void testSolvePart1Sample() {
4346

4447
// Read input file
4548
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SAMPLE);
46-
49+
50+
long result = 0;
51+
assertEquals(0, result);
4752
}
4853

4954
@Test
@@ -57,7 +62,10 @@ public void testSolvePart1Input() {
5762

5863
// Read input file
5964
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);
60-
65+
long result = 0;
66+
67+
System.out.println("R: "+result);
68+
//assertEquals(0, result);
6169
}
6270

6371
@Test
@@ -85,7 +93,10 @@ public void testSolvePart2Input() {
8593

8694
// Read input file
8795
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);
88-
96+
97+
long result = 0;
98+
System.out.println("R: "+result);
99+
//assertEquals(0, result);
89100
}
90101

91102
}

src/test/resources/inputs

0 commit comments

Comments
 (0)