I always had this question since I was a kid:
- Suppose you place 100 french fries on to a pan over a stove
- For this problem, let's assume that each french fry can only have 2 "states" : "face up" or "face down"
- Each french fry needs to be cooked for 1 minute on each side - if a french fry is cooked for more than 1 minute on any side, it is considered as burnt
- You place the french fries on the pan and after one minute you shake the pan - some of the french fries get flipped in the air and land on the pan either "face up" or "face down", but some of the french fries never got flipped at all.
- After another minute has passed, you shake the pan again.
- For the sake of this question, let's assume that each time you shake the pan, each individual french fry has a 50% chance of getting flipped in the air, and the french fries that were flipped in the air have a 50% chance of landing "face down" or "face up".
Here is the question:
- After 2 minutes, how many of the 100 french fries are perfectly cooked and how many french fries are burnt?
- How many minutes need to pass until all french fries are guaranteed to have been cooked on both sides (even though many of them will be burnt)?
Using R, I tried to write a simulation for this scenario:
original_data = data.frame(id = 1:100, state = "start") number_fries_selected_in_first_flip = sample(1:100, 1, replace=F) fries_selected_in_first_flip = sample(1:100, number_fries_selected_in_first_flip, replace=F)
This is where I got stuck - if I could somehow "tag" the french fries that were selected, I could assign a "burnt/perfectly cooked" status to these french fries with 50% probability:
status <- c("perfectly cooked","burnt") original_data$tagged_fries_status <- sample(status, number_fries_selected_in_first_flip, replace=TRUE, prob=c(0.5, 0.5))
If I could finish the simulation, I could extend the simulation for the second flip, third flip, etc. At the end of the simulation (e.g. after 5 flips), I could make a chart of the number of french fries that are burnt vs perfectly cooked. Then, I could repeat the simulation many times (e.g. 1000 times), and find out the average number of fries burnt/perfectly cooked.
Could someone please show me how to write this simulation?