Skip to content

Instantly share code, notes, and snippets.

@charusat09
Last active May 3, 2018 03:54
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/b9d507fa25e3263e3284bfb0a197ef0a to your computer and use it in GitHub Desktop.
Save charusat09/b9d507fa25e3263e3284bfb0a197ef0a to your computer and use it in GitHub Desktop.
PER_1 = 20
PER_2 = 35
PER_3 = 45
POOL_SIZE = 10
ids = [*(1..1000)]
a1 = (PER_1 / POOL_SIZE).ceil
a2 = (PER_2 / POOL_SIZE).ceil
a3 = POOL_SIZE - a1 - a2
index_1 = [*(1..a1)]
index_2 = [*(index_1.last+1..index_1.last+a2)]
index_3 = [*(index_2.last+1..POOL_SIZE)]
url_1 = []
url_2 = []
url_3 = []
ids.each do |i|
# here we are checking ids for redirecting
remender = i % POOL_SIZE
url_1 << i if index_1.include? (remender)
url_2 << i if index_2.include? (remender)
url_3 << i if (index_3.include? (remender)) || remender == 0
end
puts "*"*50
puts "url_1: #{url_1}"
puts "Count: #{url_1.count}"
puts "*"*50
puts "url_2: #{url_2}"
puts "Count: #{url_2.count}"
puts "*"*50
puts "url_3: #{url_3}"
puts "Count: #{url_3.count}"
puts "*"*50
collected_ids = (url_1 + url_2 + url_3).uniq
remaining_ids = ids - collected_ids
puts "remaining_ids: #{remaining_ids}"
puts "Count: #{remaining_ids.count}"
@charusat09
Copy link
Author

OUtput:

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

@sjdelaney
Copy link

@charusat09 This output looks promising but will defer to others that can evaluate the code itself (I am unsure if remender is supposed to be remainder).

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