Monday, November 30, 2015

几道抛硬币问题 | 四火的唠叨

几道抛硬币问题 | 四火的唠叨

只是记录一下遇到的几道抛硬币的概率问题。

 

1、平均需要抛掷多少次硬币,才会首次出现连续的两个正面?

假设连续两个正面的期望是E,那么,先看第一次抛硬币:

  1. 如果抛到反面,那么还期望抛E次,因为抛到反面完全没用,总数就期望抛E+1
  2. 如果抛到正面,那么要看下一次,如果下一次也是正面,那抛硬币就结束了,总数是2;如果下一次是反面,那么相当于重头来过,总数就期望抛E+2

于是可以得到如下关系式:

E = 0.5(E+1) + 0.25*2 + 0.25(E+2)

得到所求期望E=6

现在把题目拓展,不是说"连续两个正面",而是"连续n个正面"呢?

这个问题Matrix67有非常有趣的解答《用数学解赌博问题不稀奇,用赌博解数学问题才牛B》,下面我简述一下:

假设有一个赌场,赌博的方式就是猜正反,每来一个玩家来的时候都只带了1元,每次都会全部下注,然后赌正面,庄家抛硬币,如果猜错就是全部输掉,如果赢了就得到下注的两倍,玩家会一直玩一直玩直到钱输光;而赌场老板会看,如果有人赢到2^n元,就下令关闭赌场。

于是直到n次正面朝上的情况发生,赌场关闭,只有最后那n个人才赚到了钱,最后一人得到了2元(没算成本价1元),倒数第二人是4元……倒数第n人是2^n元,所以,一共得到(等比数列求和):

2+4+8+…+2^n = 2*(1-2^n)/(1-2) = 2^(n+1) �C 2

赌场有多少钱流入,自然就有多少钱流出,所以到赌场倒闭,玩家赢得的钱的总数,就应该等于赌场期望的收入。而因为每个人来的时候都只带了1元,因此这个数正好等于期望的人数。于是这就是最终答案。

 

2、一堆硬币,每天都随便捡一枚抛,如果抛到正面,就把它翻过来;如果抛到反面,就再抛一下,问很长很长时间以后,硬币正面和反面的比例会趋近于多少?

假设正面的比例是x,那么反面就是1-x,对于任意一次操作:

  • 如果抛到正面,那么得到的就一定是反面了;
  • 如果抛到反面,那么得到正面的可能性为0.5,反面的也为0.5。

所以得到正面的综合起来的概率为:

x*0 + (1-x)*0.5 = x

所以x = 1/3,因此硬币正面和反面的比例会趋近于x/(1-x) = 1/2

 

3、连续抛硬币,直到第一次出现连续两次正面为止,恰好抛了N次的概率是多少?

考虑"恰好"抛N次硬币,到底有多少种情况可以得出最后两次是连续出现了正面,而之前没有出现过连续正面。

  • 假设f(x)表示第一次出现连续正面的时候,已经抛了x次,并且整个过程的第一次抛出的结果是反面;
  • 假设g(x)表示第一次出现连续正面的时候,已经抛了x次,并且整个过程的第一次抛出的结果是正面。

所以f(1)=f(2)=0,g(1)=0,g(2)=1,而当x>2,

  • 求f(x+1),因为第一次是反面,所以这新添加的第一次不影响结果,因此f(x+1)=f(x)+g(x)
  • 求g(x+1),因为第一次是正面,必须要保证第二次不能为正,所以g(x+1)=f(x)

于是得到:

f(x+2)=f(x+1)+g(x+1)=f(x+1)+f(x)

g(x+1)=f(x)

其中,求f(x)的递推式可以看出f(x)是斐波那契数列,根据它的通项公式:

几道抛硬币问题

得到f(N),也就得到了g(N),而总抛的可能性共有2^N次方,因此,概率为:

(f(N)+g(N))/2^N

 

 

4、抛硬币N次,出现连续M次正面的概率是多少?

这个问题也很常见,但是做起来没那么容易,这里有一个非常详细的讨论过程(链接),我就不搬过来了。

 

5、抛N次硬币,正反两面出现次数相同的概率是多少?

其实就是从N个硬币的空位中,选出N/2个作为正面,余下N/2个作为反面,应用组合公式可得到:

C(N,N/2)/2^N=N!/((N-N/2)!(N/2)!)/2^N

继续,

正面出现次数超过反面的概率?

因为正反情况相同,因此正面次数超过反面的概率应当等于反面次数超过正面的概率,因此结果为1减去上面那一问的结果之后除以2:

(1-C(N,N/2)/2^N)/2


Read full article from 几道抛硬币问题 | 四火的唠叨

Friday, November 27, 2015

智力题以及概率题 - Backyard of LixinZhang

智力题以及概率题 - Backyard of LixinZhang

一个是如果两个质数中间只有一个数,那么证明他能被6整除?

分析

G,E,A,B,C,D,F

  • 设三个数为A,B,C。因为A,C为质数,一定不是偶数,则B一定为偶数。
  • 因为不长为三的一定会出现被3整除的数字,由于A,C为质数不能被三整除,因此A的左边E和C的右边D一定不能被三整除。
  • 那么E的左边G必须能被3整除,因为不能可能连续的3个数都不能被三整除,因此B=G+3,能被3整除,其又能被二整除,因此必须能被6整除,证毕。

Read full article from 智力题以及概率题 - Backyard of LixinZhang

Saturday, November 21, 2015

Coupon collector's problem

https://en.wikipedia.org/wiki/Coupon_collector%27s_problem
the coupon collector's problem describes the "collect all coupons and win" contests. It asks the following question: Suppose that there is an urn of n different coupons, from which coupons are being collected, equally likely, with replacement. What is the probability that more than tsample trials are needed to collect all n coupons? An alternative statement is: Given n coupons, how many coupons do you expect you need to draw with replacement before having drawn each coupon at least once? The mathematical analysis of the problem reveals that the expected number of trials needed grows as \Theta(n\log(n)).[1] For example, when n = 50 it takes about 225[2] trials to collect all 50 coupons.

赠券收集问题
赠券收集问题的特征是开始收集时,可以在短时间内收集多种不同的赠券,但最后数种则要花很长时间才能集齐。例如有50种赠券,在集齐49种以后要约多50次收集才能找到最后一张,所以赠券收集问题的答案t的期望值要比50要大得多。
以一个例子来说明:有种食品每袋都会附赠一张卡片,共有10种卡片,每种卡片出现的概率相等。
首先来求当拥有i种卡片时,再拆开一袋得到不同卡片的概率Pi:
a. 当我们没有任何卡片时,随意拆开就能得到一种不同的卡片,即第一种得到的卡片P0 = 1
b. 当有了一种继续拆,此时得到新的种类的概率为P1 = 9 / 10
...当有了i种,此时得到新种类的概率为Pi = (10 - i) / 10
我们知道了Pi的值,那么对于拆了i包后,拆开发现新卡片的次数期望为E = Pi * Ni,由于只需要然其发生一次即可令E=1反过来求对应的Ni,Ni = 1 / Pi,即拆1 / Pi包时可以发现一种新卡片(相对于已经拥有i种卡片)。
那么发现全部卡片总共需要的包数 = N0 + N1 + N2 ... N9 = 10 / 10 + 10 / 9 + 10 / 8 ... 10 / 1 = 29.289682539682538
即按期望来,买30包可以集齐卡片。
下面给出了卡片等概率出现时,集齐卡片的期望次数:
1 1.0
2 3.0
3 5.5
4 8.33333333333
5 11.4166666667
6 14.7
7 18.15
8 21.7428571429
9 25.4607142857
10 29.2896825397
11 33.2186507937
12 37.2385281385
13 41.3417388167
14 45.5218725719
15 49.7734348984
16 54.0916638917
17 58.4723928849
18 62.9119454075
19 67.4070534857
20 71.9547931429
21 76.5525328
22 81.1978915048
23 85.888704755
24 90.6229962661
25 95.3989544438
26 100.214912622
27 105.069332338
28 109.960789091
29 114.88796013
30 119.849613928
31 124.844601059
32 129.871846254
33 134.930341449
34 140.019139675
35 145.137349666
36 150.284131085
37 155.458690281
38 160.660276505
39 165.888178519
40 171.141721557
41 176.420264596
42 181.723197879
43 187.049940686
44 192.399939306
45 197.7726652
46 203.167613315
47 208.584300561
48 214.022264403
49 219.481061578
50 224.960266916
51 230.459472255
52 235.978285436
53 241.516329387
54 247.073241262
55 252.648671656
56 258.242283868
57 263.853753223
58 269.482766437
59 275.129021031
60 280.792224777
61 286.47209519
62 292.168359046
63 297.880751933
64 303.609017837
65 309.352908741
66 315.11218426
67 320.886611294
68 326.675963702
69 332.480021991
70 338.298573035
71 344.131409792
72 349.978331057
73 355.839141211
74 361.713649994
75 367.601672291
76 373.503027922
77 379.417541447
78 385.345041986
79 391.285363037
80 397.238342316
81 403.203821595
82 409.181646553
83 415.171666632
84 421.173734905
85 427.18770794
86 433.21344568
87 439.250811328
88 445.299671228
89 451.359894765
90 457.431354256
91 463.513924859
92 469.607484473
93 475.711913652
94 481.827095519
95 487.952915684
96 494.089262165
97 500.236025313
98 506.393097739
99 512.560374246
100 518.737751764
101 524.925129282
102 531.122407789
103 537.329490219
104 543.546281386
105 549.772687938
106 556.008618299
107 562.253982622
108 568.50869274
109 574.772662118
110 581.045805807
111 587.328040405
112 593.619284012
113 599.919456191
114 606.228477927
115 612.546271593
116 618.872760911
117 625.207870919
118 631.551527936
119 637.903659528
E = n / n + n / (n-1) + n/ (n-2) ... n / 1
当卡片出现的概率不是相等的时候,Pi的计算过程就麻烦许多

Wednesday, November 18, 2015

Inclusion–exclusion principle

https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle
the inclusion–exclusion principle is a counting technique which generalizes the familiar method of obtaining the number of elements in the union of two finite sets; symbolically expressed as
 |A \cup B| = |A| + |B| - |A \cap B|,
The principle is more clearly seen in the case of three sets, which for the sets AB and C is given by
|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|.
http://math.illinoisstate.edu/day/courses/old/305/contentderangements.html
Suppose we want to determine the number of derangements of the n integers 1,2,...,n for n bigger than 2. Let us focus on k and move it into the first position. We thus have started a derangement, for 1 is not in its natural position. Where could 1 be placed? There are two cases we could consider: either 1 is in position k or 1 is not in position k.
If 1 is in position k, here's what we know: The integers 1 and k have simply traded positions.
Prohibited Value
1
2
3
...
k-1
k
k+1
...
n
Derangement
k
?
?
...
?
1
?
...
?
Indicated by the question marks, there are (n-2) integers yet to derange. This can be done in D(n-2) ways.
If 1 is not in position k, we don't know as much. Note that we have shown 1 as a prohibited value twice. This is required for this case, because we cannot have 1 appear in the first position (its natural position) nor can 1 appear in position k.
Prohibited Value
1
2
3
...
k-1
1
k+1
...
n
Derangement
k
?
?
...
?
?
?
...
?
Indicated by the question marks, there are now (n-1) integers yet to derange. This can be done in D(n-1) ways.
Putting this together, we have D(n-1) + D(n-2) possible derangements when k is in the first position. How many different integers could we put in position 1 and carry out this process? All the integers except 1. that is, (n-1) different integers.
This yields the recursive formula D(n) = (n-1)[D(n-1) + D(n-2)]. As long as we know D(1) = 0 and D(2) = 1, we can generate subsequent values for D(n).

Tuesday, November 10, 2015

Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity

Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity

Innocents and Criminals: Finding Minority Entity

Problem: There are two types of people in a particular city, innocents and criminals. All you know is that innocents are in majority and would like to get rid of criminals and criminals would like to protect themselves from persecution. You can ask any number of questions, with yes/no type answer, from any person in the city. Propose an algorithm which requires asking the minimum number of questions.

Read full article from Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity

Puzzles, Maths and Algorithms: Math Magician

Puzzles, Maths and Algorithms: Math Magician

A magician has one hundred cards numbered 1 to 100. He puts them into three boxes, a red one, a white one and a blue one, such that each box contains atleast one card. A member of audience draws two cards from two different boxes and announces the sum of the number on those cards. Given this information magician locates the box from which no card has been drawn. How many ways are there to put the cards in the boxes so that the trick works.
Source: International Maths Olympiad 2000

Answer: 12

Solution:
We split the possible arrangements into two different cases.

Case 1: Assume that there exists an i such that i, i+1, i+2 go in different box (say wrb). Since, (i+1) + (i+2) = i + (i+3) => (i+3) should go in white box. Similarly i-1 should go in blue box. Since the pattern repeats without much choice so it boils down to assigning different boxes to first three cards. Total of 6 ways.

Case 2: Assume that no three neighbors are put in different boxes. Let card 1 be in white box. Let i be the smallest card to go in red box (such that i > 2). Let j be the smallest card to go in blue box (such that j < 100). Let j > i.

==> i-1 is in white box.
==> i + j = (i-1) + (j+1)
==> j+1 is in white box.

==> i + (j+1) = (i+1) + j
==> i+1 is in blue box
==> j = i+1

This violates the main assumption from both ends i-1, i, i+1 are in different boxes and also i, i+1, i+2, hence j = 100. so that j+1 doesn't exist and both 99 and 98 belong to same box other than blue.

also (i-1) + 100 = i + 99 => card 99 is in red box => card 98 is in red box

but 2 + 99 = 1 + 100 => 2 is red. in general assume that there exists a card c (>1) and it belongs to white box and also c-1 to white box. => c + 99 = (c-1) + 100. which leads to failure of the trick. Assuming cards surrounding c are red. c + 99 = c-1 + 100 => failure of trick. Hence no such c exists and c=1 is the only card in white box.

hence the combination looks like wrrrr.........rrrrrb i.e. one card (value 1) in white box, one card (value 100) in blue box and rest all cards in red box. There are six ways of such arrangements.

Read full article from Puzzles, Maths and Algorithms: Math Magician

Puzzles, Maths and Algorithms: Number and Age of David's Kids

Puzzles, Maths and Algorithms: Number and Age of David's Kids

Problem: The product of the ages of David's children is the square of the sum of their ages. David has less than eight children. None of his children have the same age. None of his children is more than 14 years old. All of his children is at least two years old. How many children does David have, and what are their ages?

Read full article from Puzzles, Maths and Algorithms: Number and Age of David's Kids

Puzzles, Maths and Algorithms: Unbiased Coin Tossing

Puzzles, Maths and Algorithms: Unbiased Coin Tossing
Given a biased coin, with probability of Heads equal to x. How to do unbiased coin tossing?
Lets define an event, E as tossing the biased coin twice. The possible outcomes with probabilities is as follows

P(h,h) = x^2
P(h,t) = x(1-x)
P(t,h) = x(1-x)
P(t,t) = (1-x)^2

The event h,t or t,h are equi-likely, without any bias we can call that if Event h,t occurs it means head, t,h means tails but if h,h or t,t occurs we repeat the experiment.

Try to find the expected number of coin toss that would be required to call heads or tails?
Let expected coin toss be e.

Probability that we get outcome in 1st event is 2x(1-x)
Total number of coin toss would be 2
Probability that we get no outcome in 1st event is [1 - 2x(1-x)]
Total number of coin toss would be 2 + e (we wasted 2 coin toss and still we expect e)

==> e = 2 * 2x(1-x) + (2+e) * [1 - 2x(1-x)]
==> e = 4x(1-x) + 2 - 4x(1-x) + e - 2ex(1-x)
==> e = 1/ [x(1-x)]

so for x = 1/2, e = 4
for x=2/3, e = 4.5
for x=1, e = INF (as expected, because all we get is chain of h h h h h)

What is the probability that there wont be any outcome in e coin tosses (expected outcomes)?
p = prob of e heads + prob of e tail
==> p = x^e + (1-x)^e

To find a bound on this p in polynomial terms can be done by using binomial expansion and Newtonian series is out of the scope of this blog. But some number crunching is.

For x = 1/2, e = 4, p = 0.125
For x = 2/3, e = 4.5, p = 0.168
For x = 3/4, e = 5.33, p = 0.216
For x = 0.99, e = 101, p = 0.362

This tells us that probability that outcome comes is quite good even for high coin biases.

How can we improve on the expected number of coin tosses?
In above method, we say that HT or TH terminates experiment. and continue the experiment a fresh when the outcome is HH or TT.

We can further combine outcome of two such events to increase the probability of outcome e.g. say HH TT => heads and TT HH means tails.

How much expected coin tosses are we doing in this case?

Read full article from Puzzles, Maths and Algorithms: Unbiased Coin Tossing

Puzzles, Maths and Algorithms: Stick Breaking

Puzzles, Maths and Algorithms: Stick Breaking
Problem Set 1: Given a stick of length 1 meter. It is cut into two parts randomly.
  • Problem 1a: What is the expected length of the smaller stick?
  • Problem 1b: What is the expected length of the bigger stick?

Problem Set 2: Given a stick of length 1 meter. It is cut into three parts randomly.
  • Problem 2a: What is the expected length of the smallest stick?
  • Problem 2b: What is the expected length of the largest stick?
  • Problem 2c: What is the expected length of the stick with second smallest (or second largest) length?
  • Problem 2d: What is the expected length of the middle stick (stick that is between the two cuts)?
  • Problem 2e: What is the probability that the three sticks would form a triangle?
  • Problem 2f: What is the probability that the three sticks would form a right angle triangle?
  • Problem 2g: What is the probability that the three sticks would form an equilateral triangle?

Problem Set 3: Given a stick of length 1 meter. It is cut into two parts randomly. Then bigger stick is picked and is again cut into two parts randomly.
  • Problem 3a: What is the expected length of the smallest stick?
  • Problem 3b: What is the expected length of the largest stick?
  • Problem 3c: What is the expected length of the stick with second smallest (or second largest) length?
  • Problem 3d: What is the expected length of the middle stick (stick that is between the two cuts)?
  • Problem 3e: What is the probability that the three sticks would form a triangle?
  • Problem 3f: What is the probability that the three sticks would form a right angle triangle?
  • Problem 3g: What is the probability that the three sticks would form an equilateral triangle?

Generalized Cut Problem: Find the solution to problem 2a-2c, 3a-3c for n-1 cuts.

Let us work out solution for 1a. Smaller stick has length x which is uniformly distributed in the range [0,0.5]. The probability distribution of x is p(x) = 1 / [1/2-0] = 2. Yes it is a pdf, ∫ 00.5p(x)dx = 1. The expected length of the smaller stick is E[x] = ∫ x p(x) dx = ∫ 00.52xdx = 1/4.

2a) Let us work out solution for 2a. Let two cuts are at distance x,y from one end. Let x < y. So the three sticks are of length x, y-x, 1-y. Let z = min(x,y-x,1-y) represent the minimum length of the stick. Let Pr(z>a) indicate the probability that min length stick has length greater than a.

=> Pr(z>a) = 2 * Pr(x>a, y-x>a, 1-y>a) = Pr(x>a, a+x < y < 1-a)

Note multiplication by 2 is for the other case (x > y). Since a+x< y < 1-a, we get x < 1-2a. Also setting x =a, we get a < 1/3 (which is obvious).

=> Pr(z > a) = 2 ∫ a1-2a ∫ a+x1-adxdy = (1-3a)2

So we get Pr(z<=a) = 1-Pr(z>a). And Pr(z=a) = derivative of Pr(z<=a) at a = 6(1-3a).

=> E[a] =  ∫ 01/36a(1-3a)da = 1/9

2b) We can do a similar derivation for z = max(x,y-x,1-y) to get the expected max length. It would be slightly more complicated. Unlike above, we compute here Pr(z< a)

=> Pr(z < a) = Pr(x < a, y-x < a, 1-y < a) = Pr( 1-2a < x < a, 1-a < y < x + a).

We need to be careful here are respect constraints like x > 0, x < y, y < 1. To ensure these constraints are respected. Pr(z < a) is broken into three cases, Case 1: a < 1/2. Case 2: a >= 1/2, 0 < x < 1-a, Case 3:  a >= 1/2, 1-a < x < a. Then we have to take differential of obtained Pr(z < a) to get Pr(z=a). [Dont mix terms from the three cases].

Integrate the first case from [1/3 to 1/2]. Second and third case from [1/2 to 1]. We will see the desired output as 1/2+1/9=11/18. (Don't forget to multiply by 2 to cover for x > y case).

2c) It would be easy to obtain: 1 - (2a) - (2b) = 1 - 1/9 - 1/2 - 1/9 = 1/2 - 2/9 = 5/18.

2d) Since there are no constraints, expected length of middle cut is 1/3

2e) For triangle, we require satisfaction of three inequalities
 x + y - x > 1-y,
 x + 1- y > y - x,
 y - x + 1 - y > x
Apart from the implicit x < y inequality.

=> 1/2 < y < x + 1/2, x < 1/2

So x follows a pdf of P(x) = 2. y satisfied the range with probability x. So the probability of triangle formation is  ∫ 01/22 x dx = 1/4.

2f) There are discrete stick lengths, e.g. (3/12, 4/12, 5/12) that satisfy this property. There are countably infinite, yet the area encapsulated by them is 0.

Problem set 3 is slightly more complicated. Let us work out 3a).

Let the first cut is at length x from shorter side (x < 1/2). Now from the stick of length (1-x), we make a cut at random of length y. Let y < (1-x)/2. If x is the shortest stick then x < y => x < 1/3.

Case 1: 1/3 < x < 1/2, 0 < y < (1-x)/2 => y is the shortest stick

Case 2: 0 < x < 1/3
    Case 2a: 0 < y < x => y is the shortest stick
    Case 2b: x < y < (1-x)/2 => x is the shortest stick

We also note that P(x) = 2 (a uniform distribution in [0,1/2]), P(y) = 2/(1-x) (a uniform distribution in [0, (1-x)/2]).

So the Expected min length = ∫ 1/31/2 ∫ 0(1-x)/2 4y/(1-x) dx dy + ∫ 01/3 ∫ 0x 4y/(1-x) dx dy + 
                                               ∫ 01/3∫ x(1-x)/24x/(1-x) dx dy = 15/16 - 2 log(3/2)

For Generalized problem read David and Nagaraja's Order Statistics (pp. 133-135, and p. 153)

The solutions through Monte-Carlo simulations. Following python code solves problem set 2 and 3. 
from random import random
def prob2():
    niter = 100000
    n, ntri, nrtri = 0.0, 0, 0
    lsmall, llarge, lmid, lcenter = 0, 0, 0, 0

    while n < niter:
        n += 1
        p = random()
        q = random()
        x = min(p, q)
        y = max(p, q)

        l1 = x
        l2 = y-x
        l3 = 1-y

        mn = min(l1, l2, l3)
        mx = max(l1, l2, l3)
        md = 1 - mn - mx
        lsmall += mn
        llarge += mx
        lmid += md
        lcenter += y

        if l1 + l2 > l3 and l1 + l3 > l2 and l2 + l3 > l1:
            ntri += 1

        if mn**2 + md**2 == mx**2:
            nrtri += 1

    print 'min len:', lsmall/n
    print 'max len:', llarge/n
    print 'mid len:', lmid/n
    print 'center stick len', lcenter/n
    print 'triangle prob:', ntri/float(n)
    print 'right triangle prob:', nrtri/float(n)

def prob3():
    niter = 100000
    n, ntri, nrtri = 0.0, 0, 0
    lsmall, llarge, lmid, lcenter = 0, 0, 0, 0

    while n < niter:
        n += 1
        p = random()
        q = random()

        l1 = 0.5 * (1-p)
        l2 = 0.25 * (1+p) * (1-q)
        l3 = 0.25 * (1+p) * (1+q)

        mn = min(l1, l2, l3)
        mx = max(l1, l2, l3)
        md = 1 - mn - mx
        lsmall += mn
        llarge += mx
        lmid += md
        lcenter += (l2+l3)/2

        if l1 + l2 > l3 and l1 + l3 > l2 and l2 + l3 > l1:
            ntri += 1

        if mn**2 + md**2 == mx**2:
            nrtri += 1

    print 'min len:', lsmall/n
    print 'max len:', llarge/n
    print 'mid len:', lmid/n
    print 'center stick len', lcenter/n
    print 'triangle prob:', ntri/float(n)
    print 'right triangle prob:', nrtri/float(n)
Read full article from Puzzles, Maths and Algorithms: Stick Breaking

Monday, November 9, 2015

Probability Puzzle - PrismoSkills

Probability Puzzle - PrismoSkills

Puzzle: If the probability of observing a car in 20 minutes on a highway is 609/625, what is the probability of observing a car in 5 minutes (assuming constant default probability)?


Solution: Probability of not seeing the car in 20 minutes = (1 - 609/625) = 16/625
If P be the probability of not seeing the car in 5 minutes, then PxPxPxP = 16/625
=> P = 2/5
=> Probability of seeing the car in 5 minutes = (1 - 2/5) = 3/5

Read full article from Probability Puzzle - PrismoSkills

选择爱人的数学方法(经典秘书问题) - tenos - 博客园

选择爱人的数学方法(经典秘书问题) - tenos - 博客园

选择爱人的数学方法(经典秘书问题)

Kepler(开普勒,1571年12月27日-1630年11月15日),德国天文学家、数学家,十七世纪科学革命的关键人物。

这样一位伟大的人物在1611年遇到一个问题,他的夫人患匈牙利斑疹伤寒(Hungarian spotted feve)过世,为了照顾孩子、打理家务,Kepler 需要重新寻找一位夫人。身为严谨的科学家,他认真记录下了"面试"11位夫人"候选人"的过程。

第一位,"口臭",Kepler写到。

1400550466.jpg

第二位,"养尊处优"。

1400550536.jpg

第三位:"已经许配给一个有私生子的人,太复杂了"。

1400550575.jpg

第四位:"身材高挑,气质不凡"。

1400550618.jpg

不过,Kepler 想看看第五个,因为有人告诉他,第五位女孩儿集"谦虚、节俭、勤奋..."等优点于一身。于是,Kepler 犹豫了,而且犹豫了很长时间,以至于第四位和第五位女孩儿都不耐烦地离开了。

第六位是一个"衣着华丽的大小姐",这把Kepler吓了一跳,他有点担心高昂的婚礼费用。

1400550660.jpg

第七位女孩儿很迷人,Kepler 也很喜欢她。由于没看完这11位"候选人",Kepler 心有不甘。他让这位女孩儿等他看完"候选人"再做决定。不愿意等人的第七位女孩儿也离开了。

1400550747.jpg

第八位女孩儿,Kepler 没怎么关心。

1400550784.jpg

第九位女孩儿"体弱多病";第十位女孩儿有着"对于没什么要求的普通人"也没办法接受的体型;最后一位女孩儿,还是个小姑娘,也不适合。

11位"候选人"都看完了,一个也没有约成。Kepler 开始想,哪里出错了?

1400550842.jpg

Kepler 所需要的,是优化策略,一种不能保证成功但能将失望降至最低的方法。数学家们觉得,我们能算出这样的公式来。                                     本文地址

如果你有自己的候选列表,爱人也好,约会也好,工作也好,这方法都管用。规则很简单:只要你的选择有限,你可以做一个列表,然后挨个来。再一次声明,不总能成功。但对数学家来说,足够了。

这个问题甚至有个名字:(开普勒的)婚姻问题。后来,又被衍生为经典秘书问题(Classic Secretary Problem)。比如,你有20个候选人要逐一面试,在面试之后,你必须决定要不要。要,选择结束;不要,那就喊下一位。不能回头。一旦决定聘用,问题结束。

根据马丁・加德纳在1960年的说法,最好的办法是,先面试前36.8%的候选人,但不录用他们。在此之后,一旦遇到比前面这36.8%里最好的还好的,立马录用。

为什么是36.8%呢?这个答案牵扯到e,1/e=0.368(关于这个概率的证明可以参考 维基百科)。很显然,这个公式经过了无数次的验证。尽管它不能保证结果最优,但你有36.8%的机会。对于11个"候选人"来说已经足够了。

如果,当时Kepler 用了这个公式,会怎样呢?11的36.8%的是4,所以他要pass掉前四位候选人,从第五位开始,只要比前四位好,Kepler 就应该求婚。也就是,经过一番折腾后,Kepler 会和第五位女孩儿结婚。(你还见记得第五位是谁吗?)

如果Kepler 当时知道这个公式(这也是当今数学上最优停止的一个例子),他便能省去后后面一批人的约会了。


Read full article from 选择爱人的数学方法(经典秘书问题) - tenos - 博客园

Labels

Popular Posts