Skip to content

Instantly share code, notes, and snippets.

@cpfiffer
Created January 17, 2017 09:07
Show Gist options
  • Save cpfiffer/9ba4aef8b2f06170f7c39ce7a2fde4f4 to your computer and use it in GitHub Desktop.
Save cpfiffer/9ba4aef8b2f06170f7c39ce7a2fde4f4 to your computer and use it in GitHub Desktop.
Solves for the birthday candle riddle at FiveThirtyEight
#The riddle can be found at https://fivethirtyeight.com/features/how-long-will-it-take-to-blow-out-the-birthday-candles/
tests = 10000000
blows <- rep(0,tests)
i = 1
while (i <=tests) {
candles = 30
while (candles > 0) {
blown_out = sample(1:candles, 1)
candles = candles - blown_out
blows[i] <- blows[i] + 1
}
i = i+1
}
mean(blows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment