Answer:
Our answer is 20 codes
Explanation:
We can not apply normal permutation or combination to solve this question. Thus we list all the possible cases and count them.
Things to note while making a code:
Rule 1. The four digit code must have distinct digits out of the set {1,2,3,4,5}.
Rule 2. Positive difference between any two consecutive digits must be atleast 2.
Now, we enlist all the codes possible starting with 1:
Because of Rule 1 and 2, the possible starting two digits of code are : 13, 14 and 15.
13 : The third digit can only be 5, Hence 135X. Now, the fourth digit can only be 2. Thus, 1352 (1 code)
14 : The third digit can only be 2. Hence 142X. Now, the fourth digit can only be 5. Hence, 1425 (1 code)
15 : Third digit can be either 2 or 3. When the initial three digits are 152, there are no possible choices for fourth digit. When the initial three digits are 153, the only possible fourth digit is 4. Hence, 1524 (1 code)
Thus there are 3 codes starting with 1.
Proceeding in similar manner for 2,3,4 and 5 as initial digits, we get the following codes:
Initial digit 2 : 2413, 2415, 2531, 2513, 2514 (5 codes)
Initial digit 3 : 3142, 3152, 3524, 3514 (4 codes)
Initial digit 4 : 4253, 4251, 4135, 4153, 4152 (5 codes)
Initial digit 5 : 5142, 5241, 5314 (3 codes)
Thus no. of possible codes : 3+5+4+5+3 = 20 codes