3 ms·
I wrote the algorithm to solve it but it's taking forever. Is the following approach correct? I'm able to get result when I set difficulty to 1,2,3 but anything
by mattfrommars 8y ago
I wrote the algorithm to solve it but it's taking forever. Is the following approach correct? I'm able to get result when I set difficulty to 1,2,3 but anything above it is taking a long time to compute.
#JavaScript
block{..}
function calculateHash(block){
return sha1(block.blockNumber+block.parentHash+block.difficulty+block.resumeHash+block.position+block.name+block.minedBy+block.nonce);
}
function mineBlock(block,difficulty) {
while (calculateHash(block).substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
block.nonce++;
console.log(block.nonce)
}
console.log("BLOCK MINED: " + this.hash);
}
mineBlock(block,<custom_difficulty_level>) // try with 1,2,3 ..it works.
console.log(calculateHash(block))