Skip to content

Instantly share code, notes, and snippets.

@jasiek
Created November 23, 2017 14:34
Show Gist options
  • Save jasiek/6992847e48551390e5a3c6093544c851 to your computer and use it in GitHub Desktop.
Save jasiek/6992847e48551390e5a3c6093544c851 to your computer and use it in GitHub Desktop.
require 'securerandom'
N = 1_000_000
M = 16
s = Array.new(N) { SecureRandom.hex(M) }
s.sort!
def lcs(a, b)
M.times do |i|
return i if a[i] != b[i]
end
return M
end
buckets = Hash.new(1)
s.each_cons(2) do |a, b|
l = lcs(a, b)
buckets[l] += 1
end
puts buckets.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment