Two (non leading zero) five digit positive integers A and B together uses the digits 0 to 9 exactly once, with B=3*A
What are A and B, if the concatenated form of the first three digits of B is a perfect square?
Satisfying first few criteria:
[[20583, 61749], [23058, 69174], [30582, 91746], [32058, 96174], [16794, 50382], [17694, 53082]]
All criteria met ... A and B are: [32058, 96174]
-----------
from itertools import permutations
from itertools import combinations
ds = '0123456789'
ab_possibles = []
ans = []
for comb in combinations(ds,5):
other5 = [i for i in ds if i not in comb]
for perm1 in permutations(comb):
if perm1[0] == '0':
continue
a = int(''.join(perm1))
for perm2 in permutations(other5):
if perm2[0] == '0':
continue
b = int(''.join(perm2))
if b == 3*a:
ab_possibles.append([a,b])
print('Satisfying first few criteria:')
print(ab_possibles)
for ab in ab_possibles:
isSquare = int(ab[1]/100)
if (round(isSquare**.5))**2 == isSquare:
print('\n', 'All criteria met ... A and B are:', ab)
|
Posted by Larry
on 2023-06-08 12:55:07 |