Skip to content

Commit 3f7ef02

Browse files
committed
feat(01/2015): solve second part
1 parent b10c6f5 commit 3f7ef02

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
8989
|----------------------------------------------------------|:------:|-----------------:|-----------------:|
90-
| [Day 1: Not Quite Lisp](src/solutions/year2015/day01.rs) | | 0.013 | - |
90+
| [Day 1: Not Quite Lisp](src/solutions/year2015/day01.rs) | | 0.013 | 0.001 |
9191

9292
# TODO
9393

src/solutions/year2015/day01.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,22 @@ impl Solution for Day01 {
1515
.to_string()
1616
}
1717

18-
fn part_two(&self, _input: &str) -> String {
19-
String::from("0")
18+
fn part_two(&self, input: &str) -> String {
19+
let mut current_flor = 0;
20+
21+
for (i, b) in input.bytes().enumerate() {
22+
current_flor += match b {
23+
b'(' => 1,
24+
b')' => -1,
25+
_ => 0,
26+
};
27+
28+
if current_flor == -1 {
29+
return (i + 1).to_string();
30+
}
31+
}
32+
33+
unreachable!()
2034
}
2135
}
2236

@@ -36,4 +50,10 @@ mod tests {
3650
assert_eq!("-3", Day01.part_one(")))"));
3751
assert_eq!("-3", Day01.part_one(")())())"));
3852
}
53+
54+
#[test]
55+
fn part_two_example_test() {
56+
assert_eq!("1", Day01.part_two(")"));
57+
assert_eq!("5", Day01.part_two("()())"));
58+
}
3959
}

0 commit comments

Comments
 (0)