I have found two ways to solve this problem analytically - the first not so rigorous and the second more rigorous. First method: Let A be the event student A rolls a twelve which has a probability of 1/36. Then the expected number of rolls for A to roll a 12 is 36 which can easily be calculated from the following equation: (1) E(A trials) = 1/36 + 35/36*[ E(A trials)+1] solving this equation leads to E(A trials)=36. in general if the probability per trial is p the expected number of trials till success is 1/p. For B the calculation is a little more complicated: (2) E(B trials) = 1/6*[1/6 * 2 + 5/6 * (E(B trials) + 2)] + 5/6* [E(B trials)+1] solving this equation leads to E(B trials) = 42. Now comes the non-rigorous part - effectively the expected value of B rolling consecutive 7's being equal to 42 rolls corresponds to a 1/42 chance on each roll even though this does not correspond to the actual B events (for example B can't win on the first roll). So using these relative probabilities in a standard way: P(A) = 1/36 P(B) = 1/42 P(A)/[P(A)+P(B)] = 7/13 probability A wins before B wins. This is the correct answer 0.538461 as the simulations confirm.
Now for the more rigorous way. Essentially this a Markov chain analysis (For reference see P. 364 Introduction to Probability - Bertsekas, Tsitsiklis). There are 4 states in the chain - two are absorbing - one where A wins I will call a12, the other where B wins I will call a77. The other two states are transient states, the start state which I will denote by as, and the state where the previous roll was a 7, I will denote by a17. Each variable (as, a17, a77, a12) represents the probability of ending in the final state where A wins (i.e. a roll of 12 before two consecutive 7's) given that they are starting in the current state represented by the variable. The following equations apply: a12 = 1 a77 =0 a17 = 29/36 * as + 6/36 * a77 + 1/36 * a12 as = 6/36 * a17 + 29/36 * as + 1/36 * a12