Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Probability to Lose All Money

A few days ago I found someone asking an interview questions on mitbbs. The question is as follows. A gambler plays a fair game and bet 1 dollar each time. If he lose all his money, the game stops. Suppose he has 10 dollars and is only allowed to play …

The Power of Generating Functions

Generating functions is a very powerful way to find closed formula for sequences defined iteratively. I was so bored during the final week, so I went on internet for fun. Finally I found someone from Sydney University was asking for help on this question:

(a) If Ln=Ln-1+Ln-2 for …

Working with Class in C++

Illustrative examples for the following discussions can be found here.

  1. It is suggested that you also provide a default constructor if you ever provide a user-defined constructor when writing a C++ class.

  2. If you want to allow deleting a derived class from a pointer of the base class, you have …

Generating YYYYMM Formatted Dates Using Python

import monthdelta as md
import datetime as dt
import math as math

def quarter(month):
    return int(math.ceil(month/3.0))
#end def

d0 = md.date.today()
dates = [d0 + md.monthdelta(i) for i in range(1, 20)]
yyyymms = [d.year*100 + d.month for d in dates]
yymms …

Don't Do Statistics If You Don't Really Undestand It

Lies, damned lies, and statistics.

As a statistician I'm very glad to see that statistics is being widely used in many areas. However, time after time I found that it is really dangerous for people who don't really understand statistics to use it. As we all know that there are …