February 24, 2014

生日悖论的排列解法

问题是:当一个房间里的人数必须达到多少,才能使至少有两个人生日相同的机会达到50%?假设一年是365天,而且每个人的生日是平均分布在每一天的。

首先,至少有两个人生日相同,表示有多人生日相同也是符合要求的,那我们就采用补的方法,至少有两个人生日相同的概率等于1减去所有人的生日都互异的概率。\(P_1\) 表示所有人生日互异的概率。

February 23, 2014

调和级数的趣题

今天看《算法导论》中的随机算法段落的时候,看到了一个公式

。查了一下Wiki知道这是个调和级数,还知道了一个有趣的题目”橡皮筋上的蠕虫”。

August 28, 2013

Javascript和Ruby中的回调

看到一片文章讲的是Javascript的异步回调,然后我想Javascript的callback是不是都是异步的? 找到一篇阮一峰的文章, 里面的一段代码其实有点问题。

在回调函数中的一个例子其实不能反应出回调的异步。

June 24, 2011

Android - Managing Multiple BroadcastReceivers

When I was developing the Presently Android client I ran into an interesting problem. If a user is in the main timeline activity and a new message comes in, the active timeline just needs to update with the new message. However, if the user is in another activity stream, (like viewing @ replies or DM’s for example) and a new message comes in to the main stream the application should not only update the main stream but should also show the user a notification so they can be aware that new messages are coming into another activity.

May 24, 2011

How to use the Application object of Android

We know there is an Application class in the Android api and according to the class name it’s used for global settings or running entrance. What does it to do for an application? I will dive into it along with some examples in this blog post.


1%