Flipping Coins : Probability of Sequences vs Probability of Individuals Here is a problem I thought of:

*

*Suppose I am watching someone flip a fair coin. Each flip is
completely independent from the previous flip.

*I watch this person flip 3 consecutive heads.

*I interrupt this person and make the following offer: If the next flip results in a "head", I will buy you a slice of pizza; if the next flip results in a "tail", you will buy me a slice of pizza.

My Question: Who has the better odds of winning?

I wrote the following simulation using the R programming language. In this simulation, a "coin" is flipped many times ("1" = HEAD, "0" = TAILS). We then count the percentage of times HEAD-HEAD-HEAD-HEAD appears compared to HEAD-HEAD-HEAD-TAILS:
#load library
library(stringr)

#define number of flips
n <- 10^7

#flip the coin many times
set.seed(1)
flips = sample(c(0,1), replace=TRUE, size=n)

#count the percent of times HEAD-HEAD-HEAD-HEAD appears 
str_count(paste(flips, collapse=""), '1111') / n

0.0333663

#count the percent tof times HEAD-HEAD-HEAD-TAIL appears
str_count(paste(flips, collapse=""), '1110') / n

0.0624983

From the above analysis, it appears as if the person's luck runs out: after 3 HEADS, there is a 3.33% chance that the next flip will be a HEAD compared to a 6.25% chance the next flip will not be a HEAD (i.e. TAILS).
Thus, could we conclude: Even though the probability of each flip is independent from the previous flip, it becomes statistically more advantageous to observe a sequence of HEADS and then bet the next flip will be a TAILS? Thus, the longer the sequence of HEADS you observe, the stronger the probability becomes of the sequence "breaking"?

By default, str_count does not count overlapping occurrances of the specified pattern.  The substring 1111 can overlap with itself substantially, whereas the substring 1110 cannot overlap with itself.  Consequently, your calculation for the first substring is substantially biased --- you are substantially undercounting the number of times this pattern actually occurs in your simulation.  Try this alternative method instead:
#Flip the coin many times
set.seed(1)
n     <- 10^8
FLIPS <- sample(c(0,1), size = n, replace = TRUE)

#Count the proportion of occurrences of 1-1-1-1
PATTERN.1111 <- FLIPS[1:(n-3)]*FLIPS[2:(n-2)]*FLIPS[3:(n-1)]*FLIPS[4:n]
sum(PATTERN.1111)/n
[1] 0.06246614

#Count the proportion of occurrences of 1-1-1-0
PATTERN.1110 <- FLIPS[1:(n-3)]*FLIPS[2:(n-2)]*FLIPS[3:(n-1)]*(1-FLIPS[4:n])
sum(PATTERN.1110)/n
[1] 0.0624983

With this alternative simulation (which counts overlapping occurrences of the patterns) you get proportions for the two outcomes that are roughly the same.   ​If the coin flips are in fact independent and "fair" then each player has the same probability of winning the wager.  Mathematically, the true probability of any run of four outcomes is $1/2^4 = 0.0625$, so that it what the above simulations are effectively estimating; the remaining small disparity in the simulation is due to random error.
