Truth and Lie Problem in Probability A fair die is rolled once and the outcome is observed by person $A$. $A$ then reports the outcome to person $B$ and $B$ writes it on a paper slip which shows that $6$ appeared on the die. Given that $A$ speaks the truth $3$ out of $4$ times and $B$ writes the truth (i.e, what A told him) $7$ out of $8$ times, what is the probability that $6$ actually appeared on the die? Given that when $A$ and $B$ are lying they tell or write a random number from $1$ to $6$ other than the one which they have observed (in case of $A$) or been told (in case of $B$).
Since I'm not that good at math so I made a code that imitated the given scenario and iterated it a billion times. The probability, thus obtained, approached $0.1107$. But I want to solve this problem mathematically.
Let $B$ be the event that $B$ writes $6$ and $R$ be the event that a $6$ was rolled.  We need to calculate $$P(R|B)=\frac{P(R\cap B)}{P(B)}$$



Let $p$ be the probability that $A$ tells the truth. The probability that $B$ is told that a $6$ was rolled is $$\frac16p+\frac56(1-p)\left(\frac15\right)=\frac16p+\frac16(1-p)=\frac16$$ since either a $6$ is rolled and $A$ tells the truth or a $6$ is not rolled, $A$ lies, and $A$ chooses to report a $6$ among all possible false values.  Therefore, the probability that $A$ reports $6$ to $B$ is $\frac16$ -- independent of the probability that $A$ tells the truth.

Obviously, the same calculation applies to the second half.  There is a $\frac16$ probability that $B$ is told to write a 6 and that is the probability that he will write a $6$ independently of how trustworthy he is.  Thus, $P(B)=\frac16$.



Now we need to find $P(R\cap B)$, the probability that both a $6$ was rolled and written.  For this, we do need the trustworthiness probabilities.  To have a 6 rolled and written, we need a six rolled AND (either A and B both tell the truth or A and B both lie and B chooses to write 6), which is $$\frac16(\frac34\cdot\frac78+\frac14\cdot\frac18\cdot\frac15)=\frac{53}{480}$$

Thus $$P(R|B)=\frac{{53}/{480}}{1/6}=\frac{53}{80}$$
Nefore you look at the paper the probability that a $6$ was rolled is $1/6$.

If you want to see how that probability changes when you know  B wrote $6$, draw a tree showing all the scenarios, with probabilities

roll 6 (probability 1/6)
   A reports 6 (probability 3/4)
       B writes 6
       B writes 1-5
   A reports 1-5 (probability 1/4)
       B writes 6
       B writes 1-5
roll 1-5 (probability 5/6)
   A reports 1-5 truthfully (probability 3/4)
       B writes 6
       B writes 1-5
   A reports 1-5 when lying (probability ??)
       B writes 6
       B writes 1-5
   A reports 6 when lying (probability ??)
       B writes 6
       B writes 1-5


Finish the tree, then multiply the probabilities down each branch  and sum the ones where B wrote $6$. Find the fraction of that when you sum the paths that start with a roll of $6. You will have to decide what happens when A or B lies.