about prisoners and selection of numbers Each of the three prisoners had a natural number written on their foreheads: 1, 2 or 3. Numbers can be repeated.  The prisoners see all numbers except their own.  After that, everyone tries to guess their number.  If someone succeeds, the prisoners will be released, otherwise they will be executed.  Before the trial, the prisoners can agree.  How can they get out?
(prisoners cannot hear each other during the trial)
I thought that 1st prisoner can do this.
if he sees two identical numbers in front of him, then he will say the same number and thus one of the prisoners will definitely be right if all the numbers are the same, and if the first prisoner sees different numbers, then he will say the third number which was not there and thus the prisoners will be  right in the case of three different digits.  but after that I don't know how the other 2 prisoners should act, they already know that in the case with three different numbers and the case with three identical numbers, the first one has already taken over, so it is necessary to choose one number from the two that they see.  But how can they choose to be right in all cases?
 A: Your solution does not work.  If the people get numbers $a,a,b$ the two people who got $a$ will see $a,b$ and guess $c$, while the person who got $b$ will see $a,a$ and guess $a$.  Nobody is right.
One way to think about the problem is that if each person guesses randomly, on average there will be $1$ correct guess.  You need one correct guess, so you need to make sure you only get one.  In your solution, if the numbers are $a,a,a$ or $a,b,c$ everybody will guess right.  You can't afford that because you are using up too many right guesses in those cases and you don't have enough left for the other case.
Instead, let one person assume that the sum of the numbers is a multiple of $3$, one assume that the sum is one more than a multiple of $3$, and the last assume that the sum is two more than a multiple of $3$.  Now exactly one person will be right however the numbers are distributed.  If the numbers are $1,2,3$ in the order given, the person with $1$ will see $2,3$ and assume that the sum is a multiple of $3$, so guess $1$ correctly.  The person with $2$ will see $1,3$ and guess $3$, while the person with $3$ will see $1,2$ and guess $2$.  I leave it to you to verify this works in all cases.
