The title

Look at the following addition:

The same characters represent the same number, and different characters represent different numbers.

Please fill in the four digits represented by “Three Sheep Xianrui” (the answer is only one), do not fill in any extra content.

parsing

A preliminary look at the formula shows that three is one (two-digit added carry), so the sum is nine, the sheep is zero, and the rest is determined by enumeration

code

public static void main(String[] args) { for (int b=2; b<9; ++b){ for (int d = 2; d < 9; ++d) { if (b==d)continue; for (int g = 2; g < 9; ++g) { if (g==b || g==d)continue; int c = b+1; if (c==b||c==d||c==g)continue; if (c+g<=10)continue; int sum = 9000 + b * 100+c*10+d+1000+g*10+b; for(int i = 2; i<9; ++i){ if (i==b||i==d||i==g||i==c)continue; if (sum<=(10000+c*100+b*10+i)&& sum>=(10000+c*100+b*10+i)){ System.out.printf("%2d%d%d%d\n", 9,b,c,d); System. The out. Printf (" % 2 d % d % d % d \ n ", 1, 0, g, b); System.out.printf("%d\n", sum); System.out.printf("----------\n"); } } } } } } }Copy the code

The results of

9567

1085

10652