# 5 Digit Code Puzzle

We have a 5 digit code, any place can take 1 2 or 3.

How do I find where the 2 is placed (if placed) knowing this criteria?

1) If the 1st digit is not a 3 then the 2nd is.

2) If the 1st digit is 3 then the 3rd digit is 2.

3) If 2nd digit is 3 and 4th is 2 then 5th is 1.

4) If the 3rd digit is not 2 then the 4th is 2.

5) If 3rd digit is not 2 then the 5th digit is not 1.

• Welcome to Puzzling! Where is the source of this puzzle? Please note that questions from other places must be credited correctly (and make sure you have permission to use them!) – Deusovi Dec 15 '18 at 14:04
• Hello there,the puzzle is made by me so i am the source(?),my inspiration started after starting computer science logic. – Agaeus Dec 15 '18 at 14:13
• May I suggest using the letters A,B and C instead of numbers for the code, that would make them a lot easier to distinguish from the ubiquitous "Nth digit" numbers. – Bass Dec 15 '18 at 16:57
• I think real answer is: Any place!! ;). – shA.t Dec 16 '18 at 12:40

The only thing we can say for sure is that

the $$3^{rd}$$ digit is a $$2$$. The other positions can be anything.

Proof:

If the $$1^{st}$$ digit is a $$3$$ then we are done.

If not, then digit:$$2$$ is a $$3$$. Now assume digit:$$3$$ is not a $$2$$, therefore digit:$$4$$ is a $$2$$ (by (4)), and so digit:$$5$$ is a $$1$$ (by (3)).

However (5) tells us that if digit:$$2$$=3 and digit:$$4$$=2, then digit:$$5$$ is not $$1$$, which is a contradiction, so digit:$$3$$=2.

For the other digit positions, these codes, $$13231,23213,31211,32222$$, contain a $$1$$, $$2$$ or $$3$$ in every other position.

Using some JavaScript:

 s=[];
for (a=1;a<4;a++)
for (b=1;b<4;b++)
for (c=1;c<4;c++)
for (d=1;d<4;d++)
for (e=1;e<4;e++) {
if (a!=3 && b!=3) continue;
if (a==3 && c!=2) continue;
if (b==3 && d==2 && e!=1) continue;
if (c!=2 && d!=2) continue;
if (c!=2 && e==1) continue;
s.push(''+a+b+c+d+e);
}
console.log(s);


we get:

$$13211,13212,13213,13221,13231,\\13232,13233,23211,23212,23213,\\ 23221,23231,23232,23233,31211,\\31212,31213,31221,31222,31223,\\ 31231,31232,31233,32211,32212,\\32213,32221,32222,32223,32231,\\ 32232,32233,33211,33212,33213,\\33221,33231,33232,33233$$

which is $$39$$ codes in total.

• You mean rot13("vs gur svefg qvtvg vf guerr") at the start of the proof? May I also suggest putting the proof first, then picking two examples to show rot13(gjb pna nyfb tb va nal bgure cbfvgvba), then the program as a postscript. – deep thought Dec 15 '18 at 18:26

Using the corrected program by @JonMarkPerry,

i.e. by changing if (c!=3 && d!=2) continue; to if (c!=2 && d!=2) continue;

We get

13211, 13212, 13213, 13221, 13231, 13232, 13233, 23211, 23212, 23213, 23221, 23231, 23232, 23233, 31211, 31212, 31213, 31221, 31222, 31223, 31231, 31232, 31233, 32211, 32212, 32213, 32221, 32222, 32223, 32231, 32232, 32233, 33211, 33212, 33213, 33221, 33231, 33232, 33233

Which means

the third position is always 2, and others may be also.