Pólya urn flip and roll
JavaScript (ES7), 145 ... 129 124 123 bytes
Takes input as (r)(n)
. This is a naive solution that actually performs the entire simulation.
r=>g=(n,B=s=0,R=0,h=d=>++d<7?h(d,[0,d].map(b=>g(n,B/-~!!b,R/-~!b)&g(n,B+b,R+d-b))):s/24**-~n)=>n--?h``:s+=~B<=r*~R|~R<=r*~B
Try it online!
Too slow for the last 2 test cases.
Commented
r => // r = target ratio
g = ( // g is a recursive function taking:
n, // n = number of iterations
B = // B = number of blue beads, minus 1
s = 0, // s = number of times the target ratio was reached
R = 0, // R = number of red beads, minus 1
h = d => // h = recursive function taking d = 6-sided die value
++d < 7 ? // increment d; if d is less than or equal to 6:
h( // do a recursive call to h:
d, // using the new value of d
[0, d].map(b => // for b = 0 and b = d:
g( // do a first recursive call to g:
n, // leave n unchanged
B / -~!!b, // divide B by 2 if b is not equal to 0
R / -~!b // divide R by 2 if b is equal to 0
) & g( // do a second recursive call to g:
n, // leave n unchanged
B + b, // add b blue beads
R + d - b // add d - b red beads
) // end of recursive calls to g
) // end of map()
) // end of recursive call to h
: // else (d > 6):
s / 24 ** -~n // stop recursion and return s / (24 ** (n + 1))
) => // body of g:
n-- ? // decrement n; if n was not equal to 0:
h`` // invoke h with d = [''] (coerced to 0)
: // else:
s += // increment s if:
~B <= r * ~R | // either (-B-1) <= r*(-R-1), i.e. (B+1)/(R+1) >= r
~R <= r * ~B // or (-R-1) <= r*(-B-1), i.e. (R+1)/(B+1) >= r