Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity
Innocents and Criminals: Finding Minority Entity
Read full article from Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity
Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity
Read full article from Puzzles, Maths and Algorithms: Innocents and Criminals: Finding Minority Entity
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.Read full article from Puzzles, Maths and Algorithms: Math Magician
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
Lets define an event, E as tossing the biased coin twice. The possible outcomes with probabilities is as follows
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)
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.
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.
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 BreakingProbability 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)?Read full article from Probability Puzzle - PrismoSkills
选择爱人的数学方法(经典秘书问题) - tenos - 博客园
Kepler(开普勒,1571年12月27日-1630年11月15日),德国天文学家、数学家,十七世纪科学革命的关键人物。
这样一位伟大的人物在1611年遇到一个问题,他的夫人患匈牙利斑疹伤寒(Hungarian spotted feve)过世,为了照顾孩子、打理家务,Kepler 需要重新寻找一位夫人。身为严谨的科学家,他认真记录下了"面试"11位夫人"候选人"的过程。
第一位,"口臭",Kepler写到。
第二位,"养尊处优"。
第三位:"已经许配给一个有私生子的人,太复杂了"。
第四位:"身材高挑,气质不凡"。
不过,Kepler 想看看第五个,因为有人告诉他,第五位女孩儿集"谦虚、节俭、勤奋..."等优点于一身。于是,Kepler 犹豫了,而且犹豫了很长时间,以至于第四位和第五位女孩儿都不耐烦地离开了。
第六位是一个"衣着华丽的大小姐",这把Kepler吓了一跳,他有点担心高昂的婚礼费用。
第七位女孩儿很迷人,Kepler 也很喜欢她。由于没看完这11位"候选人",Kepler 心有不甘。他让这位女孩儿等他看完"候选人"再做决定。不愿意等人的第七位女孩儿也离开了。
第八位女孩儿,Kepler 没怎么关心。
第九位女孩儿"体弱多病";第十位女孩儿有着"对于没什么要求的普通人"也没办法接受的体型;最后一位女孩儿,还是个小姑娘,也不适合。
11位"候选人"都看完了,一个也没有约成。Kepler 开始想,哪里出错了?
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 - 博客园