We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f9010ca commit 401f7bcCopy full SHA for 401f7bc
src/solutions/year2015/day04.rs
@@ -5,19 +5,17 @@ pub struct Day04;
5
6
impl Solution for Day04 {
7
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);
+ (0u64..)
+ .find(|answer| {
+ let hash = format!("{}{}", input, answer);
+ let digest = compute(hash);
12
13
- let x = format!("{:x}", digest);
14
- // println!("{}", x);
15
- if &x[0..5] == "00000" {
16
- return answer.to_string();
17
- }
18
+ let x = format!("{:x}", digest);
19
20
- unreachable!();
+ x.starts_with("00000")
+ })
+ .unwrap()
+ .to_string()
21
}
22
23
fn part_two(&self, _input: &str) -> String {
0 commit comments