Created
May 7, 2009 05:06
-
-
Save burke/107927 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env ruby | |
| require 'digest/md5' | |
| def find_match(a, b) | |
| largest = 0 | |
| current = 0 | |
| (32-largest).times do |aix| | |
| (32-largest).times do |bix| | |
| offset = 0 | |
| current = 0 | |
| while a[aix+offset] == b[bix+offset] | |
| offset += 1 | |
| current +=1 | |
| break if (aix+offset)>31 or (bix+offset)>31 | |
| end | |
| if current > largest | |
| largest = current | |
| end | |
| end | |
| end | |
| return largest | |
| end | |
| x = "42" | |
| i = 0 | |
| largest = 0 | |
| loop do | |
| i += 1 | |
| old = x | |
| x = Digest::MD5.hexdigest(x) | |
| curr = find_match(old,x) | |
| if curr > largest | |
| puts "#{old} => #{x} : #{curr} (#{i} scanned)" | |
| largest = curr | |
| end | |
| 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
| #!/usr/bin/env ruby | |
| require 'digest/md5' | |
| x = "42" | |
| save = "0" | |
| i = 0 | |
| j = 0 | |
| loop do | |
| i += 1 | |
| j += 1 | |
| x = Digest::MD5.hexdigest(x) | |
| if x == save | |
| puts "Cycle found at #{x}" | |
| exit | |
| end | |
| if j == 100000 | |
| save = x | |
| print "." | |
| $stdout.flush | |
| j = 0 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment