title: Simulate Flipping French Fries in R
body: <p>I always had this question since I was a kid:</p>
  <ul>
  <li>Suppose you place 100 french fries on to a pan over a stove</li>
  <li>For this problem, let's assume that each french fry can only have 2 &quot;states&quot; : &quot;face up&quot; or &quot;face down&quot;</li>
  <li>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</li>
  <li>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 &quot;face up&quot; or &quot;face down&quot;, but some of the french fries never got flipped at all.</li>
  <li>After another minute has passed, you shake the pan again.</li>
  <li>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 &quot;face down&quot; or &quot;face up&quot;.</li>
  </ul>
  <p>Here is the question:</p>
  <ul>
  <li><strong>After 2 minutes, how many of the 100 french fries are perfectly cooked and how many french fries are burnt?</strong></li>
  <li><strong>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)?</strong></li>
  </ul>
  <p>Using R, I tried to write a simulation for this scenario:</p>
  <pre><code>original_data = data.frame(id = 1:100, state = &quot;start&quot;)
  
  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)
  </code></pre>
  <p>This is where I got stuck - if I could somehow &quot;tag&quot; the french fries that were selected, I could assign a &quot;burnt/perfectly cooked&quot; status to these french fries with 50% probability:</p>
  <pre><code>status &lt;- c(&quot;perfectly cooked&quot;,&quot;burnt&quot;)
  
  original_data$tagged_fries_status &lt;- sample(status, number_fries_selected_in_first_flip, replace=TRUE, prob=c(0.5, 0.5))
  </code></pre>
  <p>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.</p>
  <p>Could someone please show me how to write this simulation?</p>
  <p>Thank you!</p>