Let A and B be two different squares of positive integers, A < B, such that the set of base ten digits of A is the same as the set of base ten digits of B.
Find the smallest and largest value of A+B, such that A+B consists of 10 distinct digits.
B must be no larger than 9876543210;
so √B must be no larger than 99380
smallest and largest
A + B A B
1023498576 = 389667600 + 633830976
9876241305 = 68112009 + 9808129296
--------------
from itertools import combinations
dict1 = {}
for n in range(1, 99381):
s = n**2
ss = ''.join(sorted((set(str(s)))))
if ss not in dict1:
dict1[ss] = [s]
else:
dict1[ss].append(s)
dict2 = {}
for akey, alist in dict1.items():
if len(alist) < 2:
continue
sortlist = sorted(alist)
dict2[akey] = sortlist
solsDict = {}
for akey, alist in dict2.items():
n_in_list = len(alist)
for comb in combinations(alist,2):
AplusB = sum(comb)
strsum = str(AplusB)
if len(strsum) != 10:
continue
if len(set(strsum)) != 10:
continue
if AplusB not in solsDict:
solsDict[AplusB] = [[comb[0], comb[1]]]
else:
solsDict[AplusB].append([comb[0], comb[1]])
sums = sorted(solsDict.keys())
print(sums[0], solsDict[sums[0]])
print(sums[-1], solsDict[sums[-1]])
|
Posted by Larry
on 2024-04-14 10:05:40 |