File tree 1 file changed +9
-9
lines changed
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
1
import hashlib
2
2
import time
3
3
4
-
5
4
def proof_of_work (difficulty : int ) -> int :
6
5
"""
7
6
Simulates a Proof of Work mining process.
8
7
9
- The miner must find a nonce such that the hash of the nonce starts
10
- with a specific number of leading zeros (difficulty)
8
+ The miner must find a nonce such that the hash of the nonce starts
9
+ with a specific number of leading zeros (difficulty).
11
10
12
11
Args:
13
- difficulty (int): The number of leading zeros required in the hash.
12
+ difficulty (int): The number of leading zeros required in the hash.
13
+
14
14
Returns:
15
- int: The nonce value that solves the puzzle.
15
+ int: The nonce value that solves the puzzle.
16
16
17
17
Example:
18
- >>> result = proof_of_work(2) # Difficulty of 2 should be fast
19
- >>> isinstance(result, int)
20
- True
18
+ >>> result = proof_of_work(2) # Difficulty of 2 should be fast
19
+ >>> isinstance(result, int)
20
+ True
21
21
"""
22
- prefix = "0" * difficulty
22
+ prefix = '0' * difficulty
23
23
nonce = 0
24
24
start = time .time () # Timing starts
25
25
You can’t perform that action at this time.
0 commit comments