Maximum number of 3-digit numbers that can be selected such that the sum of any two numbers is NOT divisible by 5
What is the maximum number of 3-digit numbers that can be selected such that the sum of any two numbers is NOT divisible by 5?
# Run Python Program: https://py3.codeskulptor.org/#user303_DO1Dc2Ko42WEolL.py
# Question: What is maximum number of 3-didgit numbers that can be selected such that the sum of any two numbers
# is NOT divisible by 5?
num_list = range(100,1000)
#num_list = [100, 101, ... 998, 999]
sum_of_2_not_div_by_5 = [100,] # First number is 100. Its last digit is 0
# Last digit 0 added with 'any other number that is not divisible by 5'
# will result a number that will not be divisible by 5
# e.g. 100+103 = 203 9not divisible by 5
def is_sum_division_by_five(i):
'''Return True if if sum of i with onw of list item is divisible by 5'''
ret = False
for j in sum_of_2_not_div_by_5:
if (i+j)%5 == 0:
ret = True
return ret
for i in num_list:
if not is_sum_division_by_five(i):
#print('appending {}'.format(i))
sum_of_2_not_div_by_5.append(i)
print(sum_of_2_not_div_by_5)
print('Count of numbers from which any any two 3 digit numbers not divisible by 5 : {} '.format(len(sum_of_2_not_div_by_5)))
# OUTPUT
Reference
https://py3.codeskulptor.org/#user303_DO1Dc2Ko42WEolL.py
# Run Python Program: https://py3.codeskulptor.org/#user303_DO1Dc2Ko42WEolL.py
# Question: What is maximum number of 3-didgit numbers that can be selected such that the sum of any two numbers
# is NOT divisible by 5?
num_list = range(100,1000)
#num_list = [100, 101, ... 998, 999]
sum_of_2_not_div_by_5 = [100,] # First number is 100. Its last digit is 0
# Last digit 0 added with 'any other number that is not divisible by 5'
# will result a number that will not be divisible by 5
# e.g. 100+103 = 203 9not divisible by 5
def is_sum_division_by_five(i):
'''Return True if if sum of i with onw of list item is divisible by 5'''
ret = False
for j in sum_of_2_not_div_by_5:
if (i+j)%5 == 0:
ret = True
return ret
for i in num_list:
if not is_sum_division_by_five(i):
#print('appending {}'.format(i))
sum_of_2_not_div_by_5.append(i)
print(sum_of_2_not_div_by_5)
print('Count of numbers from which any any two 3 digit numbers not divisible by 5 : {} '.format(len(sum_of_2_not_div_by_5)))
# OUTPUT
[100, 101, 102, 106, 107, 111, 112, 116, 117, 121, 122, 126, 127, 131, 132, 136, 137, 141, 142, 146, 147, 151, 152, 156, 157, 161, 162, 166, 167, 171, 172, 176, 177, 181, 182, 186, 187, 191, 192, 196, 197, 201, 202, 206, 207, 211, 212, 216, 217, 221, 222, 226, 227, 231, 232, 236, 237, 241, 242, 246, 247, 251, 252, 256, 257, 261, 262, 266, 267, 271, 272, 276, 277, 281, 282, 286, 287, 291, 292, 296, 297, 301, 302, 306, 307, 311, 312, 316, 317, 321, 322, 326, 327, 331, 332, 336, 337, 341, 342, 346, 347, 351, 352, 356, 357, 361, 362, 366, 367, 371, 372, 376, 377, 381, 382, 386, 387, 391, 392, 396, 397, 401, 402, 406, 407, 411, 412, 416, 417, 421, 422, 426, 427, 431, 432, 436, 437, 441, 442, 446, 447, 451, 452, 456, 457, 461, 462, 466, 467, 471, 472, 476, 477, 481, 482, 486, 487, 491, 492, 496, 497, 501, 502, 506, 507, 511, 512, 516, 517, 521, 522, 526, 527, 531, 532, 536, 537, 541, 542, 546, 547, 551, 552, 556, 557, 561, 562, 566, 567, 571, 572, 576, 577, 581, 582, 586, 587, 591, 592, 596, 597, 601, 602, 606, 607, 611, 612, 616, 617, 621, 622, 626, 627, 631, 632, 636, 637, 641, 642, 646, 647, 651, 652, 656, 657, 661, 662, 666, 667, 671, 672, 676, 677, 681, 682, 686, 687, 691, 692, 696, 697, 701, 702, 706, 707, 711, 712, 716, 717, 721, 722, 726, 727, 731, 732, 736, 737, 741, 742, 746, 747, 751, 752, 756, 757, 761, 762, 766, 767, 771, 772, 776, 777, 781, 782, 786, 787, 791, 792, 796, 797, 801, 802, 806, 807, 811, 812, 816, 817, 821, 822, 826, 827, 831, 832, 836, 837, 841, 842, 846, 847, 851, 852, 856, 857, 861, 862, 866, 867, 871, 872, 876, 877, 881, 882, 886, 887, 891, 892, 896, 897, 901, 902, 906, 907, 911, 912, 916, 917, 921, 922, 926, 927, 931, 932, 936, 937, 941, 942, 946, 947, 951, 952, 956, 957, 961, 962, 966, 967, 971, 972, 976, 977, 981, 982, 986, 987, 991, 992, 996, 997] Count of numbers from which any any two 3 digit numbers not divisible by 5 :361
Reference
https://py3.codeskulptor.org/#user303_DO1Dc2Ko42WEolL.py
Comments
Post a Comment