Skip to content

Commit a665c33

Browse files
committed
Solved day 23 part 2
1 parent 818c756 commit a665c33

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2015'
7-
version '0.22.4'
7+
version '0.22.5'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day23/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ tpl a
2929
inc a
3030
```
3131
What is **the value in register `b`** when the program in your puzzle input is finished executing?
32+
33+
# Part Two
34+
The unknown benefactor is **very** thankful for releasi-- er, helping little Jane Marie with her computer. Definitely
35+
not to distract you, what is the value in register `b` after the program is finished executing if register `a` starts
36+
as `1` instead?

day23/src/main/java/de/havox_design/aoc2015/day23/State.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package de.havox_design.aoc2015.day23;
22

33
public class State {
4+
public State() {
5+
super();
6+
}
7+
8+
public State(int registerA, int registerB) {
9+
this();
10+
11+
this.registerA = registerA;
12+
this.registerB = registerB;
13+
}
14+
415
int processCount = 0;
516
int registerA = 0;
617
int registerB = 0;

day23/src/main/java/de/havox_design/aoc2015/day23/Turing.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ public static int solvePart2(String fileName) {
2828
}
2929

3030
public int solvePart1() {
31+
return processData(0, 0);
32+
}
33+
34+
public int solvePart2() {
35+
return processData(1, 0);
36+
}
37+
38+
private int processData(int initialA, int initialB) {
3139
List<Operation> operations = tokenStream(input, PATTERN, this::parseOperation).toList();
32-
State state = new State();
40+
State state = new State(initialA, initialB);
3341
while (state.processCount < operations.size()) {
3442
Operation operation = operations.get(state.processCount);
3543
operation.operate(state);
3644
}
3745
return state.registerB;
3846
}
3947

40-
public int solvePart2() {
41-
return 0;
42-
}
43-
4448
private List<String> readData(String fileName) {
4549
return DataReader.readData(fileName, MainClass.class);
4650
}

0 commit comments

Comments
 (0)