# Find the 4-digit code!

An agent has created a 4 digit code from the result of a maths equation involving all the digits 1-9. We know where the number 3 appears in the multiplication, but not any of the other 8 digits.

   ###
X  3#
= ####


We require the 4 digit code from the equation. Can you find it?

Edit: the brute force solution is trivial - can you find another way?

• Welcome to Puzzling.SE! Please take the tour to earn your first badge. Commented Sep 23, 2016 at 8:47

Yes, this is doable computerless without too much pain.

The sum of all the digits is 45, a multiple of 3. If the numbers are a,b,c then we know a+b+c=0 (mod 3) and ab=c, so a+b+ab=0 so (1+a)(1+b)=1 so {a,b} is either {0,0} or {1,1}, so {a,b,c} is either {0,0,0} or {1,1,1} mod 3.

The first number is being multiplied by at least 31 and giving an answer at most 9876, so it's at most floor(9876/30)<=320. Its first digit can't be 3 because we have a 3 elsewhere, so the first number begins with 1 or 2. (And then the final number begins with at least a 4.)

Now, if a,b,c are all multiples of 3 (the first of our two cases from the first paragraph) then of course the product must actually be a multiple of 9; then a,b add up to a multiple of 9 and therefore they are either 0,0 or (in some order) 3,6 mod 9. Is 0,0 possible? The second number would need to be 36 and then we readily find that the first must have digits {1,8,9}, and neither 189 nor 198 works. Is 3,6 possible? That would require the second number to be 33, which it can't be. Is 6,3 possible? The other possibility is that the second number is 39, in which case the first must be 6 mod 9. That means digits {1,6,8} or {2,5,8} or {2,6,7}. We can quickly check all six cases and find that 186x39=7254 works and the other five don't.

Otherwise, all three of our numbers are 1 mod 3. In particular the second is one of {31,34,37}. It can't actually be 31 because then the first and third numbers would have the same last digit. So the second number is 34 or 37.

OK, then what's the first? Its digits add up to 1 mod 3, and it begins with 1 or 2. So the options for digits mod 3 are: 100, 112, 121, 202, 211, 220. Here a 1 or 2 in the first digit means what it says; after that 0 means 6 or 9, 1 means one of {1,4,7}, and 2 means one of {2,5,8}. The number can't end in 5 because then the third number ends in 0, forbidden, or 5, duplicate. Neither can we use both 4 and 7, because we need one for the second number. So, taking a deep breath, we enumerate: "100" 169 196; "112" 142 148 172 178; "121" 124 154 184 127 157 187; "202" 268 298; "211" 214 217 241 271; "220" 256 259 286 289.

That's eminently checkable by hand; 14 of the 22 possibilities contain either a 4 or a 7, so we only have 30 multiplications to check. We can prune a little further (e.g., no point trying xx6 times 34 because there'll be a 4 at the end of the product; no point trying xx9 times 37 because there'll be a 3 at the end of the product) but frankly it's as easy just to check them all. And it turns out that none of these works out.

Therefore, the only solution is 186x39 = 7254.

This was easy:

186*39=7254.

I have found this by computers. This is the unique solution.

• Just out of curiosity, you could've gotten the answer even without the hint of '3' right? Commented Sep 23, 2016 at 9:06
• Specifying one digit is required to have uniqueness: see the triplets {a,b,a*b} in {{138, 42, 5796}, {157, 28, 4396}, {159, 48, 7632}, {186, 39, 7254}, {198, 27, 5346}, {297, 18, 5346}, {483, 12, 5796}}. Commented Sep 23, 2016 at 9:14
• Ahh, to narrow it down to a single answer. Thanks :) Commented Sep 23, 2016 at 9:15
• Forgot to specify no brute force solutions - see edit to puzzle! Commented Sep 23, 2016 at 9:36