Skip to content

Commit b10c6f5

Browse files
committed
feat(01/2015): solve first part
1 parent c19d479 commit b10c6f5

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,12 @@
8383
| [Day 24: Never Tell Me The Odds](src/solutions/year2023/day24.rs) || 2.406 | - |
8484
| [Day 25: Snowverload](src/solutions/year2023/day25.rs) | | - | - |
8585

86+
# 2015
87+
88+
| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
89+
|----------------------------------------------------------|:------:|-----------------:|-----------------:|
90+
| [Day 1: Not Quite Lisp](src/solutions/year2015/day01.rs) || 0.013 | - |
91+
8692
# TODO
93+
8794
- if result for given day was invalid, save it in cache and avoid sending again

src/solutions/year2015/day01.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ use crate::solutions::Solution;
33
pub struct Day01;
44

55
impl Solution for Day01 {
6-
fn part_one(&self, _input: &str) -> String {
7-
String::from("0")
6+
fn part_one(&self, input: &str) -> String {
7+
input
8+
.bytes()
9+
.map(|b| match b {
10+
b'(' => 1,
11+
b')' => -1,
12+
_ => 0,
13+
})
14+
.sum::<isize>()
15+
.to_string()
816
}
917

1018
fn part_two(&self, _input: &str) -> String {
@@ -14,13 +22,18 @@ impl Solution for Day01 {
1422

1523
#[cfg(test)]
1624
mod tests {
17-
use crate::solutions::year2024::day01::Day01;
18-
use crate::solutions::Solution;
19-
20-
const EXAMPLE: &str = r#""#;
25+
use super::*;
2126

2227
#[test]
2328
fn part_one_example_test() {
24-
assert_eq!("0", Day01.part_one(EXAMPLE));
29+
assert_eq!("0", Day01.part_one("(())"));
30+
assert_eq!("0", Day01.part_one("()()"));
31+
assert_eq!("3", Day01.part_one("((("));
32+
assert_eq!("3", Day01.part_one("(()(()("));
33+
assert_eq!("3", Day01.part_one("))((((("));
34+
assert_eq!("-1", Day01.part_one("())"));
35+
assert_eq!("-1", Day01.part_one("))("));
36+
assert_eq!("-3", Day01.part_one(")))"));
37+
assert_eq!("-3", Day01.part_one(")())())"));
2538
}
2639
}

0 commit comments

Comments
 (0)