Each of M, N and P is a 4 digit non-leading zero positive integer such that:
- M+N=P
- The digits of each of M,N and P are distinct.
- Each of M, N and P are permutations of one another.
Determine all possible triplets (M,N,P).
WLOG say that M <= N.
In that case, I find 21 examples of (M,N,P).
Without that assumption there are 42.
(I found no cases of M = N)
1503 + 3510 = 5013
1530 + 3501 = 5031
1089 + 8019 = 9108
1089 + 8091 = 9180
4095 + 4950 = 9045
4095 + 5409 = 9504
4590 + 4950 = 9540
1269 + 1692 = 2961
2691 + 6921 = 9612
1467 + 6147 = 7614
1467 + 6174 = 7641
1476 + 4671 = 6147
1746 + 4671 = 6417
2439 + 2493 = 4932
4392 + 4932 = 9324
2385 + 2853 = 5238
2538 + 3285 = 5823
2853 + 5382 = 8235
3285 + 5238 = 8523
4698 + 4986 = 9684
4896 + 4968 = 9864
21
If instead we look for 5 digit numbers, the number of solutions, again just looking at M < N, there are 522 solution, none with M = N. So 1044 allowing for those with M > N.
----------- code -----------
from itertools import permutations
from itertools import combinations
nums = '0123456789'
ct=0
for abcd in combinations(nums,4):
numbers = []
for perm in permutations(abcd):
if perm[0] == '0':
continue
numbers.append(int(''.join(perm)))
for p1 in numbers:
for p2 in numbers:
if p2 < p1:
continue
if p1 + p2 in numbers:
print(p1, '+',p2, '=',p1+p2)
ct += 1
print(ct)
|
Posted by Larry
on 2022-05-21 09:11:45 |