Created
November 8, 2008 06:08
-
-
Save chrislloyd/23033 to your computer and use it in GitHub Desktop.
This file contains 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 | |
puts '-'*10 | |
keys = %w( 121 122 123 ) | |
class String | |
def first(n=1); self[0..(n-1)]; end | |
end | |
first = keys.collect{|k|k.first} | |
p first.uniq == first ? 'awesome' : 'not' | |
second = keys.collect{|k|k.first(2)} | |
p second.uniq == second ? 'more awesome' : 'not' | |
third = keys.collect{|k|k.first(3)} | |
p third.uniq == third ? 'tha shiz' : 'not' | |
keys = %w( 111 122 133 ) | |
n = 0 | |
begin | |
n += 1 | |
start = keys.collect{|k|k.first(n)} | |
p start, n | |
end until start.uniq == start || keys == start | |
p start | |
puts '-'*10 | |
require 'digest/md5' | |
keys = Array.new(10){|n| Digest::MD5.hexdigest(n.to_s) } | |
p keys | |
start_t = Time.now | |
n = 0 | |
begin | |
n += 1 | |
start = keys.collect{|k|k.first(n)} | |
end until start.uniq == start || keys == start | |
p Time.now - start_t | |
p start | |
puts start.size == keys.size | |
puts '-'*10 | |
keys = Array.new(10, Digest::MD5.hexdigest('foo')) | |
start_t = Time.now | |
n = 0 | |
begin | |
n += 1 | |
start = keys.collect{|k|k.first(n)} | |
end until start.uniq == start || keys == start | |
p Time.now - start_t | |
p start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment