Last active
May 1, 2018 12:50
-
-
Save charusat09/ba704fee6edfd8adf485a240d52bb8df to your computer and use it in GitHub Desktop.
Zlib CRC32 alogorithm test
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
require "zlib" | |
# total percentage = 100 | |
PER_1 = 20 | |
PER_2 = 30 | |
PER_3 = 50 | |
ids = [*(1..1000)].map(&:to_s) | |
libs = [] | |
ids.each { |a| libs << Zlib.crc32(a) % 100_000 } | |
set_1 = [] | |
set_2 = [] | |
set_3 = [] | |
libs.each_with_index do |l,i| | |
if l < PER_1 * 1_000 | |
# id: ids[i] will be allowed | |
set_1 << ids[i] | |
end | |
end | |
libs.each_with_index do |l,i| | |
if l < PER_2 * 1_000 | |
# id: ids[i] will be allowed | |
set_2 << ids[i] | |
end | |
end | |
libs.each_with_index do |l,i| | |
if l < PER_3 * 1_000 | |
# id: ids[i] will be allowed | |
set_3 << ids[i] | |
end | |
end | |
puts "IDs for percentage: #{PER_1}" | |
puts set_1.join(", ") | |
puts set_1.count | |
puts "Count: #{set_1.count}" | |
puts "*"*50 | |
puts "IDs for percentage: #{PER_2}" | |
puts set_2.join(", ") | |
puts "Count: #{set_2.count}" | |
puts "*"*50 | |
puts "IDs for percentage: #{PER_3}" | |
puts set_3.join(", ") | |
puts "Count: #{set_3.count}" | |
puts "*"*50 | |
unique_ids = (set_1 + set_2 + set_3).uniq.map(&:to_s) | |
remaining_ids = ids - unique_ids | |
puts "remaining IDs" | |
puts remaining_ids.join(", ") | |
puts "Count: #{remaining_ids.count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: