Skip to content

Instantly share code, notes, and snippets.

@actsasgeek
Created August 30, 2013 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save actsasgeek/6385480 to your computer and use it in GitHub Desktop.
Save actsasgeek/6385480 to your computer and use it in GitHub Desktop.
Poincare's Bread Supposedly, Poincaré   suspected that his local bakery was selling loaves of bread that were lighter than the advertised weight of 1 kg, so every day for a year he bought a loaf of bread, brought it home and weighed it. At the end of the year, he plotted the distribution of his measurements and showed that it fit a normal distri…
pick_heaviest_loaf <- function( loaves=100) {
bread <- rnorm( loaves, 950, 50)
return( max( bread))
}
loaves_over_a_year <- function( loaves=100) {
days <- 365
poincare_loaves <- vector()
for (i in 1:days ) {
heaviest_loaf <- pick_heaviest_loaf(loaves)
poincare_loaves <- append( poincare_loaves, heaviest_loaf)
}
return( poincare_loaves)
}
loaves <- loaves_over_a_year(100)
summary( loaves)
hist( loaves)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment