Skip to content

Instantly share code, notes, and snippets.

@charusat09
Last active May 1, 2018 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charusat09/ba704fee6edfd8adf485a240d52bb8df to your computer and use it in GitHub Desktop.
Save charusat09/ba704fee6edfd8adf485a240d52bb8df to your computer and use it in GitHub Desktop.
Zlib CRC32 alogorithm test
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}"
@charusat09
Copy link
Author

charusat09 commented May 1, 2018

Output:

2, 3, 5, 23, 27, 31, 33, 36, 38, 41, 46, 53, 54, 61, 77, 80, 90, 99, 108, 109, 113, 114, 126, 127, 130, 131, 134, 146, 150, 153, 155, 156, 162, 164, 175, 178, 180, 182, 184, 190, 211, 224, 225, 237, 244, 248, 253, 254, 260, 261, 263, 273, 277, 282, 283, 292, 299, 318, 335, 337, 345, 355, 372, 375, 378, 386, 400, 402, 405, 409, 410, 411, 413, 417, 421, 422, 426, 427, 434, 443, 445, 459, 469, 474, 476, 477, 488, 490, 500, 505, 509, 511, 514, 518, 519, 521, 522, 531, 534, 536, 537, 547, 552, 555, 558, 561, 562, 565, 570, 576, 578, 585, 589, 593, 594, 601, 606, 608, 615, 618, 624, 626, 628, 629, 631, 646, 661, 662, 667, 673, 674, 676, 682, 688, 691, 698, 700, 705, 713, 717, 720, 721, 722, 738, 739, 743, 744, 746, 748, 767, 789, 790, 794, 800, 801, 805, 809, 810, 811, 816, 821, 822, 827, 842, 846, 851, 861, 865, 875, 882, 884, 885, 887, 891, 895, 898, 913, 940, 947, 952, 955, 960, 961, 962, 963, 973, 977, 979, 980, 981, 984, 989, 991, 994
194
Count: 194
**************************************************
IDs for percentage: 30
2, 3, 5, 6, 7, 8, 11, 14, 20, 23, 27, 31, 33, 36, 38, 39, 41, 46, 47, 53, 54, 57, 61, 63, 64, 67, 71, 77, 80, 87, 90, 92, 96, 99, 100, 103, 104, 108, 109, 113, 114, 116, 126, 127, 130, 131, 134, 146, 148, 150, 153, 155, 156, 162, 163, 164, 170, 174, 175, 178, 180, 182, 184, 185, 186, 190, 196, 200, 203, 205, 211, 214, 224, 225, 237, 243, 244, 248, 249, 253, 254, 260, 261, 263, 268, 273, 276, 277, 280, 282, 283, 287, 292, 296, 299, 303, 311, 312, 318, 329, 335, 337, 341, 345, 348, 355, 364, 371, 372, 375, 378, 386, 393, 400, 401, 402, 403, 405, 409, 410, 411, 413, 414, 415, 417, 421, 422, 426, 427, 434, 436, 443, 444, 445, 450, 451, 456, 457, 459, 464, 469, 474, 476, 477, 480, 481, 488, 490, 500, 505, 509, 511, 514, 518, 519, 521, 522, 526, 531, 532, 534, 536, 537, 541, 545, 547, 552, 555, 558, 561, 562, 565, 570, 576, 578, 579, 585, 589, 591, 593, 594, 600, 601, 606, 608, 615, 618, 622, 624, 625, 626, 628, 629, 631, 632, 646, 653, 660, 661, 662, 665, 667, 673, 674, 676, 682, 685, 688, 690, 691, 698, 700, 703, 704, 705, 711, 713, 717, 719, 720, 721, 722, 723, 725, 738, 739, 743, 744, 746, 748, 757, 766, 767, 774, 776, 777, 783, 789, 790, 794, 800, 801, 805, 807, 809, 810, 811, 816, 821, 822, 827, 831, 836, 837, 842, 846, 848, 851, 852, 861, 863, 865, 875, 876, 882, 884, 885, 887, 889, 891, 895, 898, 900, 902, 913, 921, 923, 924, 940, 947, 948, 952, 955, 960, 961, 962, 963, 973, 977, 979, 980, 981, 983, 984, 985, 987, 989, 991, 993, 994
Count: 300
**************************************************
IDs for percentage: 50
2, 3, 5, 6, 7, 8, 10, 11, 14, 17, 18, 20, 23, 24, 25, 26, 27, 31, 33, 35, 36, 37, 38, 39, 41, 46, 47, 48, 51, 53, 54, 55, 57, 58, 61, 62, 63, 64, 67, 69, 71, 77, 78, 79, 80, 81, 86, 87, 90, 91, 92, 93, 96, 99, 100, 103, 104, 108, 109, 113, 114, 115, 116, 123, 124, 126, 127, 128, 130, 131, 134, 146, 148, 149, 150, 153, 154, 155, 156, 158, 159, 160, 162, 163, 164, 165, 169, 170, 174, 175, 178, 180, 182, 184, 185, 186, 190, 193, 196, 199, 200, 201, 202, 203, 205, 206, 209, 210, 211, 212, 214, 217, 223, 224, 225, 232, 234, 237, 240, 243, 244, 248, 249, 253, 254, 255, 257, 260, 261, 262, 263, 267, 268, 269, 271, 272, 273, 276, 277, 280, 282, 283, 284, 287, 288, 291, 292, 296, 297, 299, 300, 302, 303, 305, 311, 312, 314, 318, 323, 324, 325, 329, 335, 337, 338, 341, 342, 345, 346, 347, 348, 351, 355, 364, 366, 370, 371, 372, 375, 378, 381, 383, 386, 390, 392, 393, 400, 401, 402, 403, 404, 405, 409, 410, 411, 412, 413, 414, 415, 417, 421, 422, 425, 426, 427, 429, 430, 431, 434, 436, 443, 444, 445, 450, 451, 453, 456, 457, 459, 462, 464, 466, 469, 471, 472, 474, 476, 477, 478, 480, 481, 484, 488, 490, 493, 497, 499, 500, 503, 505, 509, 511, 512, 514, 515, 518, 519, 521, 522, 525, 526, 530, 531, 532, 533, 534, 536, 537, 540, 541, 545, 547, 548, 549, 552, 553, 555, 557, 558, 561, 562, 565, 568, 570, 573, 576, 577, 578, 579, 582, 583, 584, 585, 587, 588, 589, 591, 593, 594, 595, 596, 600, 601, 606, 608, 609, 611, 615, 617, 618, 621, 622, 624, 625, 626, 627, 628, 629, 631, 632, 635, 640, 642, 646, 647, 648, 650, 651, 653, 656, 657, 660, 661, 662, 663, 665, 667, 671, 673, 674, 676, 682, 683, 685, 688, 690, 691, 694, 698, 700, 702, 703, 704, 705, 710, 711, 713, 714, 717, 718, 719, 720, 721, 722, 723, 725, 728, 730, 731, 736, 738, 739, 743, 744, 746, 748, 749, 750, 752, 753, 757, 758, 759, 760, 762, 763, 765, 766, 767, 770, 771, 773, 774, 776, 777, 781, 783, 788, 789, 790, 791, 793, 794, 795, 798, 800, 801, 805, 807, 809, 810, 811, 814, 816, 821, 822, 825, 826, 827, 831, 832, 833, 834, 836, 837, 840, 841, 842, 845, 846, 847, 848, 849, 851, 852, 855, 857, 861, 862, 863, 865, 868, 870, 873, 875, 876, 877, 882, 883, 884, 885, 887, 888, 889, 890, 891, 895, 896, 898, 900, 902, 906, 911, 913, 916, 917, 921, 922, 923, 924, 929, 935, 937, 938, 939, 940, 941, 942, 944, 945, 947, 948, 949, 952, 955, 956, 957, 960, 961, 962, 963, 964, 970, 973, 974, 976, 977, 979, 980, 981, 982, 983, 984, 985, 987, 988, 989, 991, 993, 994, 996
Count: 501
**************************************************
remaining IDs
1, 4, 9, 12, 13, 15, 16, 19, 21, 22, 28, 29, 30, 32, 34, 40, 42, 43, 44, 45, 49, 50, 52, 56, 59, 60, 65, 66, 68, 70, 72, 73, 74, 75, 76, 82, 83, 84, 85, 88, 89, 94, 95, 97, 98, 101, 102, 105, 106, 107, 110, 111, 112, 117, 118, 119, 120, 121, 122, 125, 129, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 147, 151, 152, 157, 161, 166, 167, 168, 171, 172, 173, 176, 177, 179, 181, 183, 187, 188, 189, 191, 192, 194, 195, 197, 198, 204, 207, 208, 213, 215, 216, 218, 219, 220, 221, 222, 226, 227, 228, 229, 230, 231, 233, 235, 236, 238, 239, 241, 242, 245, 246, 247, 250, 251, 252, 256, 258, 259, 264, 265, 266, 270, 274, 275, 278, 279, 281, 285, 286, 289, 290, 293, 294, 295, 298, 301, 304, 306, 307, 308, 309, 310, 313, 315, 316, 317, 319, 320, 321, 322, 326, 327, 328, 330, 331, 332, 333, 334, 336, 339, 340, 343, 344, 349, 350, 352, 353, 354, 356, 357, 358, 359, 360, 361, 362, 363, 365, 367, 368, 369, 373, 374, 376, 377, 379, 380, 382, 384, 385, 387, 388, 389, 391, 394, 395, 396, 397, 398, 399, 406, 407, 408, 416, 418, 419, 420, 423, 424, 428, 432, 433, 435, 437, 438, 439, 440, 441, 442, 446, 447, 448, 449, 452, 454, 455, 458, 460, 461, 463, 465, 467, 468, 470, 473, 475, 479, 482, 483, 485, 486, 487, 489, 491, 492, 494, 495, 496, 498, 501, 502, 504, 506, 507, 508, 510, 513, 516, 517, 520, 523, 524, 527, 528, 529, 535, 538, 539, 542, 543, 544, 546, 550, 551, 554, 556, 559, 560, 563, 564, 566, 567, 569, 571, 572, 574, 575, 580, 581, 586, 590, 592, 597, 598, 599, 602, 603, 604, 605, 607, 610, 612, 613, 614, 616, 619, 620, 623, 630, 633, 634, 636, 637, 638, 639, 641, 643, 644, 645, 649, 652, 654, 655, 658, 659, 664, 666, 668, 669, 670, 672, 675, 677, 678, 679, 680, 681, 684, 686, 687, 689, 692, 693, 695, 696, 697, 699, 701, 706, 707, 708, 709, 712, 715, 716, 724, 726, 727, 729, 732, 733, 734, 735, 737, 740, 741, 742, 745, 747, 751, 754, 755, 756, 761, 764, 768, 769, 772, 775, 778, 779, 780, 782, 784, 785, 786, 787, 792, 796, 797, 799, 802, 803, 804, 806, 808, 812, 813, 815, 817, 818, 819, 820, 823, 824, 828, 829, 830, 835, 838, 839, 843, 844, 850, 853, 854, 856, 858, 859, 860, 864, 866, 867, 869, 871, 872, 874, 878, 879, 880, 881, 886, 892, 893, 894, 897, 899, 901, 903, 904, 905, 907, 908, 909, 910, 912, 914, 915, 918, 919, 920, 925, 926, 927, 928, 930, 931, 932, 933, 934, 936, 943, 946, 950, 951, 953, 954, 958, 959, 965, 966, 967, 968, 969, 971, 972, 975, 978, 986, 990, 992, 995, 997, 998, 999, 1000
Count: 499

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment