READYBIT APRIL LONG CHALLENGE

Guys,how did u solve the readybit question?

1 Like

Wait for the editorial.

Let P_e(x) be the probability that an expression e evaluates to x where x \in \{0,1,a,A\}

If e is β€œ#”, P_e(x) = \frac{1}{4} forall \ x \in \{0,1,a,A\}.

You can recursively calculate P_e(x) for any e which is of the form e_1\ o \ e_2 where o is an operator and e_1,e_2 are expressions using the following pseudocode:

for x in {0,1,a,A}
    P_e(x) = 0
for x1 in {0,1,a,A}
    for x2 in {0,1,a,A}
        P_e(x o y) += P_e1(x)*P_e2(y)

We are given with infix expression. You should change it to postfix or prefix expression which will make you solve problem more easily.
Here is my source code: CodeChef: Practical coding for everyone
Above link is showing access denied due to some error, you can check code at Online Compiler and IDE >> C/C++, Java, PHP, Python, Perl and 70+ other compilers and interpreters - Ideone.com

It’s showing access denied,bro!

Check from here Online Compiler and IDE >> C/C++, Java, PHP, Python, Perl and 70+ other compilers and interpreters - Ideone.com

You can assume or transform \{0, a, A, 1\} \to \{0, 1, 2, 3\}, then the operations have their respective meanings on this set.
Now calculate the probablities recursively. Let left and right expressions have probabilties P_l and P_r, to calculate it for the new expression P(x) = \sum\limits_{u \circ v = x}{P_l(u)P_r(v)}

2 Likes