Mine for 2016 in Bitcoins! PCG.SE New Year's Puzzle 2016 In the Bitcoin protocol, 2016 is a very special number. The "difficulty" of finding a hash to create a new block is adjusted every 2,016 blocks to approximate changing once every two weeks.

This number was chosen is because the difficulty adjusts itself so that every block takes about 10 minutes to be found, and in two weeks, there are 2 &times; 7 &times; 24 &times; 6 = 2,016 ten-minute periods.



To commemorate this numerical coincidence, this year's New Year's problem is about Bitcoin — specifically, the hashing algorithm it uses to sign blocks, SHA-256.

Your task is to create a program that will take byte input (in at least ASCII) and output a nonce in bytes (in the format of your choice) that will produce a SHA-256 hash containing 2016 in its base64 representation when appended to the original byte input.

Here are some examples of valid solutions, courtesy of the engines people have already generated, as well as the hashes they produced:

&gt; foo
Nonce: 196870
SHA256 hash: OCUdDDtQ42wUlKz2016x+NROo8P2lbJf8F4yCKedTLE=

&gt; bar
Nonce: 48230
SHA256 hash: CNcaOCQgT7bnlQzQPXNwuBu8/LYEdk2016khRaROyZk=

&gt; happynewyear
Nonce: 1740131
SHA256 hash: XsKke6z2016BzB+wRNCm53LKJ6TW6ir66GwuC8oz1nQ=

&gt; 2016
Nonce: 494069
SHA256 hash: rWAHW2YFhHCr22016zw+Sog6aW76eImgO5Lh72u6o5s=

(note: the nonces don't actually have to be ASCII numbers; you can do
 any byte input you find convenient.)


The only pre-built library (other than standard input and output functions) your program may use is a SHA256(bytes) function that takes byte input and returns a SHA256 hash, in any format including base64.

The program to do this in the fewest bytes of source code wins.
Mathematica, 94

(For[i=0,IntegerDigits[4Hash[#&lt;&gt;ToString@++i,"SHA256"],64]~SequenceCount~{54,52,53,58}&lt;1,];i)&amp;


This function will try positive integers as candidates. It takes over 4 minutes on my laptop to get the correct answer.

%["foo"]
(* 196870 *)


Longer however faster (~5x) implementation makes use of parallelization: 

f[k_]:=
    Do[If[Length@#&gt;0,Return[i+#[[1,1]]]]&amp;@
        Position[ParallelMap[IntegerDigits[4Hash[k&lt;&gt;ToString@#,"SHA256"],64]
            ~SequenceCount~{54,52,53,58}&amp;,i+Range@1*^4],1]
        ,{i,0,∞,1*^4}]