Sunday, September 02, 2018

Monty Hall Problem

Today I want to talk about a game show that used to come to Star Plus, "Khullja Sim Sim". If I remember correctly, Aman Verma was the host. I just used to watch without understanding much.

During college, I read about the Monty Hall problem and it was so counter-intuitive, I could not believe it and thought of it as just a theoretical analysis and the real life situation would still be same for both the situation. Later, I forgot about it.

Very recently, I again read about it and I remembered that I was sceptical about it the last time. But, now I could write code.

So, I wrote a code which randomly puts prize in one of the three doors. Then, the player has a random first guess. The game then opens an empty gate and the player is given a chance to change his earlier choice. I tracked number of wins separately for both the situations when the player changes their first choice and when they do not.

Surprisingly (for me, not for those who understood the analysis properly), the result is better when the player chose to change their first choices. Double, to be precise.

The analysis loosely translates to the fact that, if you do not change your choice, your probability still remains 1/3 whereas, if you select, it becomes 1/2 since the second time, only two options left.

I understood the argument properly even the first time. But, did not realise how deeply the concept of probability is entangled with our day-to-day situations. It was overwhelming for me and I wanted to share this with all of you.

You can find the code here. Do let me know what do you think about the problem.

Wednesday, June 27, 2018

Something About Professional Growth

I have done job search very recently and a few years back to extend the career horizons. This post is not to provide tips, but to share one realisation that I have gone through during the process.

What happened a lot of times with me is that, it seemed to me that I would be a perfect fit for a role. My interview would go well and I would be certain that the people at the other end of discussion loved me. But, then I would get a regret mail. Whereas, I would get green signal response for roles which would not match my exact past experience. I used to be flabbergasted.

But not anymore. What I realised is that when a potential employer look at your past experience, they are trying to assess you based your past achievements and determine how you take challenging situations. Most of the time they are not looking for exact matches. Of course, for very specific roles, this is not true. But, this holds good for most of the situations.

What they want most of the time is that you have a room to grow. If you are an exact fit, you would become bored quite soon, well unless you have home loans.

I believe this is a good thing. Variety and diversity always help. Maintaining diversity in anything is helpful when things start going south, and you would not realise about problematic nature of mono-culture when things are good. I personally believe even a very technical role needs certain room to grow.

Something to think about when you do not hear positively from a potential employer for a role that exactly matches your past experiences.

Saturday, June 23, 2018

Preliminary Monte-Carlo to Find Value of Pi

This may be called Monte Carlo, but, I do not think it is a good example. Nevertheless, let us try to see. This is a product of a situation when you do not have much left to watch on Netflix.

The idea is to use the pseudo random number generator in C to get random points inside a square of sides with length 2 units. We shall try to determine if a point is lying inside the circle that is inscribed inside it. If random numbers are well spread, then ratio of number of points inside the circle to the number of points inside the square should be equal to that their respective areas.

Apart from the usual stuffs, one thing to note is that the pseudo random number generator in C is not thread-safe. The seed gets locked and its state gets changed in usual rand() call. GCC kindly provides this thread-safe version of it (rand_r()). Otherwise, with multi-threading, run-time actually increases.

Another minor thing is that since the pseudo-random numbers generation is mostly similar time consuming, default OpenMP for option (static) is best fit.

This is a plot of percentage error vs number of iteration. Probably due to pseudo part of the random numbers, we might not ever reach very close to the real value as we increase number of iteration most of the time.

You can find the code here. Please let me know your comments.