dice probability math

1r. R code for the probability of rolling n dice and having a sum roll before another sum or sums. In a general sense a 'race' between two independent events (need to be mutually exclusive or disjoint. in other words they cannot both occur at the same time. )

1st example. What is the probability while rolling 2d6 that a 6 would roll befor a 7?

2nd example is a popular text book question. What is the probability of rolling two 7s with 2d6 before rolling 6 even numbers? even numbers being from the set {2,4,6,8,10,12} and all do not have to roll, just a total of 6 with repetition .

3rd example. What is the probability of rolling 2d6 and rolling 3 sixes or eights (6 or 8) before rolling two 7s?

***** answers can be found running the R code below

results shows two values. 1st = answers the probability question where the 1st event wins the race and 2nd result = 1-p (where the 2nd event wins the race). when tails and heads = 1 the fraction will be shown before the decimal result.

***** call function example: headsBeforeTails(1,5/36,1,6/36) # one 6 before one 7

headsBeforeTails(# of 6s,probability of rolling one 6,# of 7s,probability of rolling one 7)