Skip to content

Commit 65ef18d

Browse files
committed
feat(04/2015): solve second part
1 parent 19780fd commit 65ef18d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
| [Day 1: Not Quite Lisp](src/solutions/year2015/day01.rs) | ⭐⭐ | 0.013 | 0.001 |
9191
| [Day 2: I Was Told There Would Be No Math](src/solutions/year2015/day02.rs) | ⭐⭐ | 0.074 | 0.105 |
9292
| [Day 3: Perfectly Spherical Houses in a Vacuum](src/solutions/year2015/day03.rs) | ⭐⭐ | 0.358 | 0.373 |
93-
| [Day 4: The Ideal Stocking Stuffer](src/solutions/year2015/day04.rs) | | 66.769 | - |
93+
| [Day 4: The Ideal Stocking Stuffer](src/solutions/year2015/day04.rs) | | 66.769 | 1931.428 |
9494

9595
# TODO
9696

src/solutions/year2015/day04.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@ pub struct Day04;
55

66
impl Solution for Day04 {
77
fn part_one(&self, input: &str) -> String {
8+
self.answer(input, "00000")
9+
}
10+
11+
fn part_two(&self, input: &str) -> String {
12+
self.answer(input, "000000")
13+
}
14+
}
15+
16+
impl Day04 {
17+
fn answer(&self, input: &str, starts_with: &str) -> String {
818
(0u64..)
919
.find(|answer| {
1020
let hash = format!("{}{}", input, answer);
1121
let digest = compute(hash);
1222

1323
let x = format!("{:x}", digest);
1424

15-
x.starts_with("00000")
25+
x.starts_with(starts_with)
1626
})
1727
.unwrap()
1828
.to_string()
1929
}
20-
21-
fn part_two(&self, _input: &str) -> String {
22-
String::from("0")
23-
}
2430
}
2531

2632
#[cfg(test)]

0 commit comments

Comments
 (0)