Skip to content

Commit 401f7bc

Browse files
committed
refactor(04/2015): simplify
1 parent f9010ca commit 401f7bc

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/solutions/year2015/day04.rs

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

66
impl Solution for Day04 {
77
fn part_one(&self, input: &str) -> String {
8-
for answer in 0u64.. {
9-
// println!("{}", answer);
10-
let hash = format!("{}{}", input, answer);
11-
let digest = compute(hash);
8+
(0u64..)
9+
.find(|answer| {
10+
let hash = format!("{}{}", input, answer);
11+
let digest = compute(hash);
1212

13-
let x = format!("{:x}", digest);
14-
// println!("{}", x);
15-
if &x[0..5] == "00000" {
16-
return answer.to_string();
17-
}
18-
}
13+
let x = format!("{:x}", digest);
1914

20-
unreachable!();
15+
x.starts_with("00000")
16+
})
17+
.unwrap()
18+
.to_string()
2119
}
2220

2321
fn part_two(&self, _input: &str) -> String {

0 commit comments

Comments
 (0)