# Inside Bitcoin's Proof-of-Work / Waste 10-Minute Mining Lottery - The Ruby Edition by Example

Hello,

I've put together a step-by-step article that breaks down the
"magic" of Bitcoin's proof-of-work / waste 10-minute mining lottery
[1].

including what's your hash rate per seconds [2] and many more.

Example:

```
require "digest"

def sha256( msg )
Digest::SHA256.hexdigest( msg )
end

···

#################
# Let's calculate 10 million, that is, 10 000 000 hashes.
# e.g. "Hello, world!0"
# "Hello, world!1"
# "Hello, world!2"
# "Hello, world!3"
# and on and on and on

t1 = Time.now
10_000_000.times do |i|
sha256( "Hello, world!#{i}")

# bonus: print a dot (.) for progress for every one hundred thousand
hashes calculated
print "." if i % 100_000 == 0
end
t2 = Time.now

delta = t2 - t1
puts ""
puts "Elapsed Time: %.4f seconds" % delta

hashrate = Float( 10_000_000 / delta )
puts "Hash Rate: %d hashes/second" % hashrate
```

Happy hashing and block chaining with ruby.

Bonus: Learn the secret How to Buy Bitcoin (The CO₂-Friendly Way)
by Trolly McTrollface.

Gerald,

Thanks for this stuff! I have been interested in doing something with Ruby and BTC for a while but so far have not made the time / effort - I will go through this in more detail!

Regards,

Phil.

···

On 2020-01-23 06:50, Gerald Bauer wrote:

Hello,

I've put together a step-by-step article that breaks down the
"magic" of Bitcoin's proof-of-work / waste 10-minute mining lottery
[1].

including what's your hash rate per seconds [2] and many more.

Example:

``````require "digest"

def sha256( msg )
Digest::SHA256.hexdigest( msg )
end

#################
# Let's calculate 10 million, that is, 10 000 000 hashes.
#    e.g. "Hello, world!0"
#         "Hello, world!1"
#         "Hello, world!2"
#         "Hello, world!3"
#         and on and on and on

t1 = Time.now
10_000_000.times do |i|
sha256( "Hello, world!#{i}")

# bonus: print a dot (.) for progress for every one hundred thousand
hashes calculated
print "."    if i % 100_000 == 0
end
t2 = Time.now

delta = t2 - t1
puts ""
puts "Elapsed Time: %.4f seconds" % delta

hashrate = Float( 10_000_000 / delta )
puts "Hash Rate: %d hashes/second" % hashrate
``````

Happy hashing and block chaining with ruby.

Bonus: Learn the secret How to Buy Bitcoin (The CO₂-Friendly Way)
by Trolly McTrollface.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--

PO Box 896
Cowra NSW 2794
Australia
E-mail: phil@pricom.com.au

Hello,

> interested in doing something with Ruby and BTC

FYI: Learn Me A Bitcoin [1] by Greg Walker is the ultimate (free)
in-depth resource
about learning bitcoin and the best - all (or almost all) sample code
snippets are in ruby [2].

And from my humble self you might read / browse the two (free) ruby
guides / booklets
titled:

o Programming Blockchains Step-by-Step Book / Guide [3]
Let's build blockchains from scratch (zero) step by step. Let's