Charmaine has written down three 3-digit positive integers which between them contains exactly 9 distinct digits.
Among these three positive integers:
- There is at least one that is divisible by 2.
- There is at least one that is divisible by 3.
- There is at least one that is divisible by 4.
- There is at least one that is divisible by 5.
- There is at least one that is divisible by 6.
- There is at least one that is divisible by 7.
- There is at least one that is divisible by 8.
- There is at least one that is divisible by 9.
In addition, it is known that all the three positive integers are divisible by 11.
What are the three 3-digit integers posited by Charmaine?
Note: Adapted from Enigma # 1776 which appeared in 'New Scientist' in 2013.
Answer: [165, 308, 792]
Call the concatenation abc a 3 digit number.
Since there are no 3 digit numbers divisible by 11 and with no repeat digits which end in zero, the number divisible by 5 must end in a 5
So all numbers with a 5 in the a or b position can be eliminated.
There are only 50 3 digit numbers with no repeat digits divisible by 11 with no 5s in the a or b position.
----------------
def checkdiv(alist):
""" alist is a list of 3 integers
if not div by 11, return False
if at least one number in alist is div by 2,3,...,9 return True """
for a in alist:
if a%11 != 0:
return False
counter = [0 for i in range(2,10)]
for divisor in range(2,10):
for n in alist:
if n%divisor == 0:
counter[divisor - 2] += 1
if 0 in counter:
return False
return True
elevens = []
for a in range(1,10 ):
if a == 5:
continue
for b in range(10):
if b == 5:
continue
if a==b:
continue
for c in range(10):
if a==c or b==c:
continue
x = 100*a+10*b+c
if x%11 == 0:
elevens.append(x)
from itertools import combinations
solutions = []
for comb in combinations(elevens,3):
if checkdiv(comb):
x = sorted(list(comb))
if x not in solutions:
solutions.append(x)
for s in solutions:
t = ''.join(str(s[i]) for i in range (3))
if len(t) == len(set(t)):
print(s)
|
Posted by Larry
on 2023-07-02 20:27:16 |