Last active
December 27, 2016 08:19
-
-
Save petertseng/483ef192df8e79b6f48cc16a35a83b05 to your computer and use it in GitHub Desktop.
day 15 with extra hash powers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "crypto/md5" | |
| hash = "0" * 32 | |
| zeroes = Array.new(32, 1) | |
| ROWS = 8 | |
| almost = 0 | |
| hashes = Array.new(ROWS, "") | |
| hashes[0] = hash | |
| (1..(1.0 / 0.0)).each { |t| | |
| hash = Crypto::MD5.hex_digest(hash) | |
| hashes[t % ROWS] = hash | |
| hash.each_char.with_index { |c, i| | |
| if c == '0' | |
| zeroes[i] += 1 | |
| if zeroes[i] == ROWS | |
| hit_time = t - ROWS | |
| puts "HIT at t=#{hit_time} at column #{i}" | |
| puts "t=#{hit_time} #{" " * i}*" | |
| (1..ROWS).each { |dt| | |
| row_time = hit_time + dt | |
| puts "t=#{row_time} #{hashes[row_time % ROWS]}" | |
| } | |
| puts "We came close #{almost} times!" | |
| exit 0 | |
| end | |
| else | |
| if zeroes[i] == ROWS - 1 | |
| puts "So close! at #{t}" | |
| almost += 1 | |
| end | |
| zeroes[i] = 0 | |
| end | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| So close! at 4445623 | |
| So close! at 12122100 | |
| So close! at 16570529 | |
| So close! at 27420196 | |
| So close! at 34458826 | |
| So close! at 36400105 | |
| So close! at 38363659 | |
| So close! at 79147987 | |
| So close! at 91223760 | |
| So close! at 100304390 | |
| So close! at 107333146 | |
| So close! at 107567039 | |
| So close! at 112950979 | |
| So close! at 120967557 | |
| So close! at 127208246 | |
| So close! at 139247969 | |
| So close! at 158260385 | |
| So close! at 164031321 | |
| So close! at 181484528 | |
| So close! at 183846084 | |
| So close! at 191529496 | |
| So close! at 203156255 | |
| So close! at 203932778 | |
| HIT at t=204947638 at column 13 | |
| t=204947638 * | |
| t=204947639 f1773abd2e79f01510f9c2a2b4336136 | |
| t=204947640 2a13793c429cd0fe9f803d12341f9dfd | |
| t=204947641 4a48eedba347e0fba6a4b6d5d977736c | |
| t=204947642 01e4ca27df8a3059ce2377cb81ed7ea8 | |
| t=204947643 e43d5eca6331d0b88dabb8c20aa47106 | |
| t=204947644 47462d6606bd20a74d97a1e7aea23070 | |
| t=204947645 12116b454ccd8049a4dc2cd882bd9f3f | |
| t=204947646 0132b44673c240e3d51e0cde2bcd2921 | |
| We came close 23 times! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment