Skip to content

Commit a2a6984

Browse files
committed
feat(07/2015): solve second part
1 parent d64a2fc commit a2a6984

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
| [Day 4: The Ideal Stocking Stuffer](src/solutions/year2015/day04.rs) | ⭐⭐ | 66.769 | 1931.428 |
9494
| [Day 5: Doesn't He Have Intern-Elves For This?](src/solutions/year2015/day05.rs) | ⭐⭐ | 0.261 | 0.987 |
9595
| [Day 6: Probably a Fire Hazard](src/solutions/year2015/day06.rs) | ⭐⭐ | 871.538 | 817.533 |
96-
| [Day 7: Some Assembly Required](src/solutions/year2015/day07.rs) | | 0.308 | - |
96+
| [Day 7: Some Assembly Required](src/solutions/year2015/day07.rs) | | 0.308 | 0.293 |
9797

9898
# TODO
9999

src/solutions/year2015/day07.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ impl Solution for Day07 {
1111
self.signal(input, "a")
1212
}
1313

14-
fn part_two(&self, _input: &str) -> String {
15-
String::from("0")
14+
fn part_two(&self, input: &str) -> String {
15+
let a_value = self.signal(input, "a");
16+
17+
let mut instructions = self.parse(input);
18+
instructions
19+
.entry("b".to_string())
20+
.and_modify(|v| *v = Instruction::Value(Value::Numeric(a_value.parse().unwrap())));
21+
22+
self.signal_for_instructions(&instructions, "a")
1623
}
1724
}
1825

1926
impl Day07 {
2027
fn signal(&self, input: &str, wire: &str) -> String {
2128
let instructions = self.parse(input);
22-
let main = instructions.get(wire).unwrap();
29+
30+
self.signal_for_instructions(&instructions, wire)
31+
}
32+
33+
fn signal_for_instructions(&self, instructions: &Wires, wire: &str) -> String {
2334
let mut cache = HashMap::new();
35+
let main = instructions.get(wire).unwrap();
2436

25-
main.calculate(&instructions, &mut cache).to_string()
37+
main.calculate(instructions, &mut cache).to_string()
2638
}
2739

2840
fn parse(&self, input: &str) -> Wires {

0 commit comments

Comments
 (0)