Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Vitamin C kills tumor cells with hard-to-treat mutation in mice. Parent comment
#p=Prob(tails), n=# Coins, q=Prob(heads), Npop=# times to repeat
p=.5; n=5; q=1-p; Npop=1000
#Flip one Coin 100x and find first tails (probability of getting one mutation)
OneCoin=function() which(sample(0:1,100, prob=c(q,p), replace=T)==1)[1]
#Flip n coins and find last one to turn up tails (probability of accumulating n mutations)
OneSet=function() max(replicate(n,OneCoin()))
#Repeat Npop times, like different people in a population
res=replicate(Npop,OneSet())
hist(res, breaks=Npop/20)
There are no comments on this comment yet.
#p=Prob(tails), n=# Coins, q=Prob(heads), Npop=# times to repeat
p=.5; n=5; q=1-p; Npop=1000
#Flip one Coin 100x and find first tails (probability of getting one mutation)
OneCoin=function() which(sample(0:1,100, prob=c(q,p), replace=T)==1)[1]
#Flip n coins and find last one to turn up tails (probability of accumulating n mutations)
OneSet=function() max(replicate(n,OneCoin()))
#Repeat Npop times, like different people in a population
res=replicate(Npop,OneSet())
hist(res, breaks=Npop/20)