altairahmad
Please one basic confusion
Only one digit W (0-9) will be correct and only 1 arrangement will be correct from following 4 arrangements right ?
WCCC , CWCC, CCWC, CCCW
So doesn't it mean that he will have to try 10 x 3 (3 wrong arrangements with full 10 digits) + 9 (1 correct arrangement with 1 correct digit) = 39 attempts ?
Lets say the correct code is 0009. You are given 0000. Start from the beginning (left) and work your way to the right.
You try 0000 initially (from the question) and that doesn't work. So you try nine more times: 1000, 2000, ...., 9000. Okay, they all didn't work, so try the 2nd digit now.
You don't need to try 0000 again since you did that already. You try 0100, 0200, 0300, 0400, ...., 0900. None of those work, so try the 3rd digit.
You don't need to try 0000 again since you did that already. You try 0010, 0020, 0030,....., 0090. None of those work so you try the 4th digit.
You don't need to try 0000 again since you did that already. You try 0001, 0002, 0003, and then on the last try (you're very unlucky!) 0009 works!
So 36 additional tries were needed.