Friday, April 30, 2010

Mini Betting

This little story is about the recently held IPL final.
Mumbai Indians(MI) v/s Chennai Super Kings(CSK).

Its characters are D, P1,P2,P3 .

So P1 was informed by his "friend" that CSK is gonna win the IPL.
Reason:  Lot of betting going on for MI. People are betting more on MI. If MI wins then it would be a great loss to the bookies.

P1 is happy to know that he knows the future. He goes around telling everyone about the "Plan". Now comes D. Not so sure about P1's claim, he wants to challenge P1 that if he is so sure why doesn't he put down his money in the betting market.

D : "I don't think, CSK is the winner. Just look at the stats and current form of the MI players. MI is rocking man. Totally impossible for CSK to snatch a win"
P1 : "You dont know the internals of betting. I am informed (by a trusted source) that CSK is this season's winner"

D : "Ohh...ya...why don't you bet then. if you are so sure. I am making a wager to you now. If MI wins, you give me 500 bucks and if CSK wins, I give u 100 bucks. The odds are different because you have an insider information. If you believe in your Source, then I think you should bet"
P1 :  "Deal Bro. See you at the finals."

Now D is little skeptical about the deal. If D loses, he is gonna lose about 100 bucks. He doesn't want that. D who always takes calculated risks saw this to be too risky. So he chalks out a plan to cut out his losses.

He makes another wager with P2. Now little background about P2. He is a CSK supporter.
Reason : His favourite player is the captain of CSK.

The following chat occurred between D and P2.

D : "I have a hunch. I think CSK  is gonna win. Sachin is injured and he won't be a captain at the finals. I don't trust Zaheer with captainship. So what do you say if I bet on MI losing the final."

P2 : "I am not sure. I dont know."

Now at this stage, D thinks P2 needs to be pushed a little harder.

D : " See, there is no harm in you making a deal. IF CSK wins, you will give me 100 bucks in happiness as your team won the final. If CSK loses, I will give you 100 bucks and it will be like consolation for you. In both the outcomes, its good for you"

Fortunately P2 agreed.

The deal is set for D. D is at zero risk in case of any outcome. If MI wins, he is gonna get 500 from P1 and he will hand out 100 bucks to P2. A profit of 400 bucks. If MI loses, D just transfers the money from P2 to P1.

Now comes P3 in the story. Seeing the deal between D and P1, P3 got little greedy. He wanted a piece of the action too. He told D that he is ready to divide risk and profit. If MI loses, he will pay 50 bucks to P1 and would take half the amount if MI wins.

Here's something that went wrong. Instead of accepting the offer, D said no to P3. If D had accepted the offer from P3, he would have earned a minimum of 50 bucks and a maximum of 150 bucks in either outcome of the finals. A much safer option.

The following diagrams explain the above situation.

Without P3's deal

With P3's deal :

Sunday, April 25, 2010

Proving primality : Testing whether a particular number is prime or not

Many a times computer science students are faced with problems whose sub-problem involves testing whether a chosen number is a prime or not.

Finding primes & proving primality

In the above link, you will find very good resources about primality testing and proving.

I have implemented an algorithm which lets you test whether a number  (17 < N < 341,550,071,728,321) is a prime or not.

The link to the python code is here

The code is nicely written but not well documented. You can extend the valid limit for numbers by adding extra conditions in the code.

HOPE THIS HELPS SOMEONE.

Friday, April 16, 2010

To specify default Browser for links in Thunderbird


A nice post by the name "Forcing Thunderbird to open links in Firefox"

This post talks about how to specify / force Thunderbird to open links in Firefox in Ubuntu. For sometimes now, I had this problem of not being able to directly open links from Thunderbird. The same effect can be achieved if we do the following.


The real problem was that I had not specified the default system browser in System Preferences. 
Go the Preferred Applications and specify the browser (Chrome/Firefox/Opera/Konqueror/ etc)
System->Preferences->Preferred applications

Open Thunderbird and all your links will now be opened in your default browser.
 

HOPE THAT HELPS SOMEONE OUT THERE