merkle reverse

SimonN eiderdaus at gmail.com
Thu Apr 5 08:57:11 UTC 2018


On Thursday, 5 April 2018 at 08:12:38 UTC, aerto wrote:
> This is the bitcoin genesis block merkle root 
> 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b how i can get it at this format 3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a ??
>
> i try it using
>
> string merkle = 
> "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
>
> writeln(merkle.retro.text); and it gives me
>
> b33adedfa7b7212ba77cc2e37667f816f78cb13c88a81523a3f98baab4e1e5a4

Here's one solution with std.range.chunks. A small downside is 
that it needs the array allocation in the middle because chunks 
cannot offer the bi-directional range necessary for retro.

     import std.range;
     import std.algorithm;

     void main()
     {
         string merkle =
             
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
         assert (merkle.retro.equal(
             
"b33adedfa7b7212ba77cc2e37667f816f78cb13c88a81523a3f98baab4e1e5a4"));
         assert (merkle.chunks(2).array.retro.joiner.equal(
             
"3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"));
     }

-- Simon


More information about the Digitalmars-d-learn mailing list