A password consists of four distinct digits such that their sum is 19 and such that exactly two of these digits are prime, for example 0397. The number of possibilities for the password is?

-
Though you could do it by hand, I would just crank up a computer to check the $10^4$ cases. – Ross Millikan Nov 15 '12 at 0:40
But that will give us all combinations of 4 digits from 0 to 9 with no restrictions? – John Chang Nov 15 '12 at 0:42
@JohnChang: That's where the "computer to check" comes in. It's not necessary here though. – wj32 Nov 15 '12 at 0:43
Yes, generate all combinations, check the sum. If not 19, go on to the next. If 19, check the number of primes. If not 2, go on. If 2, increment counter by 1. At end, report the value of the counter. – Ross Millikan Nov 15 '12 at 0:46
Ah. I misinterpreted. I thought your answer was 10^4. Lol. :) Sorry. – John Chang Nov 15 '12 at 0:50

So primes here are 2, 3,5, 7.

Taking 2,3, you need 14 more to get a sum of 19. This can be done with 6,8 only.

Taking 2,5, you need 12 more to get a sum of 19. This can be done with 4,8 only.

Taking 2,7, you need 10 more to get a sum of 19. This can be done with 1,9 or 4,6 only.

Taking 3,5, you need 11 more to get a sum of 19. This cannot be done.

Taking 3,7, you need 9 more to get a sum of 19. This can be done with 1,8 or 0,9 only.

Taking 5,7, you need 7 more to get a sum of 19. This can be done 1,6 only.

That gives us 6 sets each represents $4!=24$ combinations, so there are 7*24=168 possible passwords.

-

Here is a python snippet

primes = [2,3,5,7]
others = [0,1,4,6,8,9]
for i in primes:
for j in primes:
if i < j:
for k in others:
l = 19-i-j-k
if l < k and l >=0 and l not in primes:
print("%d %d %d %d" % (i,j,k,l))


Here is the output

2 3 8 6
2 5 8 4
2 7 6 4
2 7 9 1
3 7 8 1
3 7 9 0
5 7 6 1

-
Rather a lot of these have three primes such as 2395. One (3565) has the same number twice – Henry Nov 15 '12 at 1:20
Oh right, forgot one test, and edited code – Vincent Nivoliers Nov 15 '12 at 1:21

Well, we have 2, 3, 5, and 7 as our primes. Take 2 and 3. Now the problem reduces to finding $X$ and $Y$ in $23XY$ so that $2 + 3 + X + Y = 19$, $X \ne Y$, $X \ne 2$, $X \ne 3$, $Y \ne 2$, and $Y \ne 3$. You could do this by hand if you are systematic. Repeat the same process for 2 and 5, 2 and 7, etc. You could also write a Java program or ask for help at Programmers.

-
I'm getting 168 passwords. Is this correct? :) – John Chang Nov 15 '12 at 1:08
@JohnChang Yes. – glebovg Nov 15 '12 at 1:49

By hand

p1 p2 remaining other pairs
2  3     14         6,8
2  5     12         4,8
2  7     10      1,9  4,6
3  5     11          -
3  7      9      0,9   1,8
5  7      7         1,6


So $4! \times 7 = 168$ possibilities

-