Another test simulating mining, infinite possibilities and solutions.
your method does not guarantee a 100% match. the algorithm does not iterate hashes inside subblocks starting from matching the first bits to the block boundary. with a difficult of 16 bits (as in the example) for some reason you are sure that the prefix will not be repeated in less than 5000 steps, and this is not a correct assumption. two prefixes can go either one after another or not repeat for a large number of iterations. If you are unlucky, you will go through the entire 68th range and will not find the desired hash.