The all digit's sums

In how many different ways can the digits from 1 to 9 be placed into the squares (without repetition) so that the addition is valid?

If you need to use programming, it's OK. Please share your code.


The answer is 336.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Yuriy Kazakov
Aug 2, 2020
1
2
3
4
5
6
from itertools import permutations
s=0
for k in permutations([1,2,3,4,5,6,7,8,9],9):
  if (k[0]+k[3])*100+(k[1]+k[4])*10+k[2]+k[5] ==k[6]*100+k[7]*10+k[8]:
    s=s+1
print(s)

1
336

its 336 \boxed{336} , here is some code:

1
2
3
4
5
6
7
8
P = perms(1:9);
R =[];          
for k = 1:factorial(9)
    if 100*(P(k,1)+P(k,4)-P(k,7)) + 10*(P(k,2)+P(k,5)-P(k,8)) + (P(k,3)+P(k,6)-P(k,9)) == 0
        R = [R; P(k,:)] ;
    end
end
size(R,1)

Can we solve the problem without any computer program?Mr.(Goycoolea)!

Matin Naseri - 3 years, 2 months ago

Log in to reply

One could solve by inspection, finding essentially different solutions column by column and their permutations if possible, but it would be really tedious (you should take into account the possible carries).

Might be there is a cleaner way, but i haven't found any.

Jose Fernandez Goycoolea - 3 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...