Re: Ruby Quiz - Challenge #2 - Calculate the Bitcoin Genesis Block Hash (SHA-256)

"Frank J. Cameron" <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
> Challenge #2 - Calculate the Bitcoin Genesis Block Hash (SHA-256)

$ ruby lib/002.rb
Run options: --seed 62016
# Running:
.
Finished in 0.002718s, 367.9076 runs/s, 367.9076 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

$ cat lib/002.rb
require_relative '../002/test.rb'
require 'digest'
class RubyQuizTest
  def calculate(v, p, m, t, b, n)
    Digest::SHA256.digest(
      Digest::SHA256.digest(
        [v].pack('V')            \
        + [p].pack('H*').reverse \
        + [m].pack('H*').reverse \
        + [t].pack('V')          \
        + [b].pack('H*').reverse \
        + [n].pack('V')
      )
    ).reverse.unpack('H*')[0]
  end
end
RubyQuizTest.new('fjc')



Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.