Pólya urn flip and rollRoll Dungeons and Dragons diceBuild a program to analyze coin flip sequence choicesSimple single-player board game, expected score distributionSplit, flip and recombine integersYour Base to 1-2-3-Tribonacci to Binary back to Your BaseFlip a coin for me!Flip rows and columnsWhen Fibonacci meets the QueensBack to the Basics of MathSolve a matrix equation by Jacobi's method (Revised)

I am looking for the correct translation of love for the phrase "in this sign love"

Drawing ramified coverings with tikz

Creature in Shazam mid-credits scene?

Redundant comparison & "if" before assignment

How could a planet have erratic days?

Is it better practice to read straight from sheet music rather than memorize it?

How should I respond when I lied about my education and the company finds out through background check?

Fear of getting stuck on one programming language / technology that is not used in my country

Yosemite Fire Rings - What to Expect?

Why is it that I can sometimes guess the next note?

How can we generalize the fact of finite dimensional vector space to an infinte dimensional case?

why `nmap 192.168.1.97` returns less services than `nmap 127.0.0.1`?

How much character growth crosses the line into breaking the character

Non-trope happy ending?

Approximating irrational number to rational number

Create all possible words using a set or letters

It grows, but water kills it

Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed

When were female captains banned from Starfleet?

WiFi Thermostat, No C Terminal on Furnace

How do you make your own symbol when Detexify fails?

When a Cleric spontaneously casts a Cure Light Wounds spell, will a Pearl of Power recover the original spell or Cure Light Wounds?

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Not using 's' for he/she/it



Pólya urn flip and roll


Roll Dungeons and Dragons diceBuild a program to analyze coin flip sequence choicesSimple single-player board game, expected score distributionSplit, flip and recombine integersYour Base to 1-2-3-Tribonacci to Binary back to Your BaseFlip a coin for me!Flip rows and columnsWhen Fibonacci meets the QueensBack to the Basics of MathSolve a matrix equation by Jacobi's method (Revised)













13












$begingroup$


Problem statement



Pólya is playing about with his urn again and he wants you to help him calculate some probabilities.



In this urn experiment Pólya has an urn which initially contains 1 red and 1 blue bead.



For every iteration, he reaches in and retrieves a bead, then inspects the colour and places the bead back in the urn.



He then flips a fair coin, if the coin lands heads he will insert a fair 6 sided die roll amount of the same coloured bead into the urn, if it lands tails he will remove half the number of the same colored bead from the urn (Using integer division - so if the number of beads of the selected colour is odd he will remove (c-1)/2 where c is the number of beads of that colour)



Given an integer n ≥ 0 and a decimal r > 0, give the probability to 2 decimal places that the ratio between the colours of beads after n iterations is greater than or equal to r in the shortest number of bytes.



An example set of iterations:



Let (x, y) define the urn such that it contains x red beads and y blue beads.



Iteration Urn Ratio
0 (1,1) 1
1 (5,1) 5 //Red bead retrieved, coin flip heads, die roll 4
2 (5,1) 5 //Blue bead retrieved, coin flip tails
3 (3,1) 3 //Red bead retrieved, coin flip tails
4 (3,4) 1.333... //Blue bead retrieved, coin flip heads, die roll 3


As can be seen the Ratio r is always ≥ 1 (so it's the greater of red or blue divided by the lesser)



Test cases:



Let F(n, r) define application of the function for n iterations and a ratio of r



F(0,5) = 0.00
F(1,2) = 0.50
F(1,3) = 0.42
F(5,5) = 0.28
F(10,4) = 0.31
F(40,6.25) = 0.14


This is code golf, so the shortest solution in bytes wins.










share|improve this question











$endgroup$











  • $begingroup$
    I feel like there is a formula for this...
    $endgroup$
    – Embodiment of Ignorance
    Mar 15 at 18:10










  • $begingroup$
    Something to do with beta binomials maybe, but it might be longer to write that out
    $endgroup$
    – Expired Data
    Mar 15 at 18:13










  • $begingroup$
    depends on the language; R and Mathematica might be able to do it efficiently.
    $endgroup$
    – Giuseppe
    Mar 15 at 20:45















13












$begingroup$


Problem statement



Pólya is playing about with his urn again and he wants you to help him calculate some probabilities.



In this urn experiment Pólya has an urn which initially contains 1 red and 1 blue bead.



For every iteration, he reaches in and retrieves a bead, then inspects the colour and places the bead back in the urn.



He then flips a fair coin, if the coin lands heads he will insert a fair 6 sided die roll amount of the same coloured bead into the urn, if it lands tails he will remove half the number of the same colored bead from the urn (Using integer division - so if the number of beads of the selected colour is odd he will remove (c-1)/2 where c is the number of beads of that colour)



Given an integer n ≥ 0 and a decimal r > 0, give the probability to 2 decimal places that the ratio between the colours of beads after n iterations is greater than or equal to r in the shortest number of bytes.



An example set of iterations:



Let (x, y) define the urn such that it contains x red beads and y blue beads.



Iteration Urn Ratio
0 (1,1) 1
1 (5,1) 5 //Red bead retrieved, coin flip heads, die roll 4
2 (5,1) 5 //Blue bead retrieved, coin flip tails
3 (3,1) 3 //Red bead retrieved, coin flip tails
4 (3,4) 1.333... //Blue bead retrieved, coin flip heads, die roll 3


As can be seen the Ratio r is always ≥ 1 (so it's the greater of red or blue divided by the lesser)



Test cases:



Let F(n, r) define application of the function for n iterations and a ratio of r



F(0,5) = 0.00
F(1,2) = 0.50
F(1,3) = 0.42
F(5,5) = 0.28
F(10,4) = 0.31
F(40,6.25) = 0.14


This is code golf, so the shortest solution in bytes wins.










share|improve this question











$endgroup$











  • $begingroup$
    I feel like there is a formula for this...
    $endgroup$
    – Embodiment of Ignorance
    Mar 15 at 18:10










  • $begingroup$
    Something to do with beta binomials maybe, but it might be longer to write that out
    $endgroup$
    – Expired Data
    Mar 15 at 18:13










  • $begingroup$
    depends on the language; R and Mathematica might be able to do it efficiently.
    $endgroup$
    – Giuseppe
    Mar 15 at 20:45













13












13








13


4



$begingroup$


Problem statement



Pólya is playing about with his urn again and he wants you to help him calculate some probabilities.



In this urn experiment Pólya has an urn which initially contains 1 red and 1 blue bead.



For every iteration, he reaches in and retrieves a bead, then inspects the colour and places the bead back in the urn.



He then flips a fair coin, if the coin lands heads he will insert a fair 6 sided die roll amount of the same coloured bead into the urn, if it lands tails he will remove half the number of the same colored bead from the urn (Using integer division - so if the number of beads of the selected colour is odd he will remove (c-1)/2 where c is the number of beads of that colour)



Given an integer n ≥ 0 and a decimal r > 0, give the probability to 2 decimal places that the ratio between the colours of beads after n iterations is greater than or equal to r in the shortest number of bytes.



An example set of iterations:



Let (x, y) define the urn such that it contains x red beads and y blue beads.



Iteration Urn Ratio
0 (1,1) 1
1 (5,1) 5 //Red bead retrieved, coin flip heads, die roll 4
2 (5,1) 5 //Blue bead retrieved, coin flip tails
3 (3,1) 3 //Red bead retrieved, coin flip tails
4 (3,4) 1.333... //Blue bead retrieved, coin flip heads, die roll 3


As can be seen the Ratio r is always ≥ 1 (so it's the greater of red or blue divided by the lesser)



Test cases:



Let F(n, r) define application of the function for n iterations and a ratio of r



F(0,5) = 0.00
F(1,2) = 0.50
F(1,3) = 0.42
F(5,5) = 0.28
F(10,4) = 0.31
F(40,6.25) = 0.14


This is code golf, so the shortest solution in bytes wins.










share|improve this question











$endgroup$




Problem statement



Pólya is playing about with his urn again and he wants you to help him calculate some probabilities.



In this urn experiment Pólya has an urn which initially contains 1 red and 1 blue bead.



For every iteration, he reaches in and retrieves a bead, then inspects the colour and places the bead back in the urn.



He then flips a fair coin, if the coin lands heads he will insert a fair 6 sided die roll amount of the same coloured bead into the urn, if it lands tails he will remove half the number of the same colored bead from the urn (Using integer division - so if the number of beads of the selected colour is odd he will remove (c-1)/2 where c is the number of beads of that colour)



Given an integer n ≥ 0 and a decimal r > 0, give the probability to 2 decimal places that the ratio between the colours of beads after n iterations is greater than or equal to r in the shortest number of bytes.



An example set of iterations:



Let (x, y) define the urn such that it contains x red beads and y blue beads.



Iteration Urn Ratio
0 (1,1) 1
1 (5,1) 5 //Red bead retrieved, coin flip heads, die roll 4
2 (5,1) 5 //Blue bead retrieved, coin flip tails
3 (3,1) 3 //Red bead retrieved, coin flip tails
4 (3,4) 1.333... //Blue bead retrieved, coin flip heads, die roll 3


As can be seen the Ratio r is always ≥ 1 (so it's the greater of red or blue divided by the lesser)



Test cases:



Let F(n, r) define application of the function for n iterations and a ratio of r



F(0,5) = 0.00
F(1,2) = 0.50
F(1,3) = 0.42
F(5,5) = 0.28
F(10,4) = 0.31
F(40,6.25) = 0.14


This is code golf, so the shortest solution in bytes wins.







code-golf probability-theory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 15 at 15:40







Expired Data

















asked Mar 15 at 15:15









Expired DataExpired Data

2665




2665











  • $begingroup$
    I feel like there is a formula for this...
    $endgroup$
    – Embodiment of Ignorance
    Mar 15 at 18:10










  • $begingroup$
    Something to do with beta binomials maybe, but it might be longer to write that out
    $endgroup$
    – Expired Data
    Mar 15 at 18:13










  • $begingroup$
    depends on the language; R and Mathematica might be able to do it efficiently.
    $endgroup$
    – Giuseppe
    Mar 15 at 20:45
















  • $begingroup$
    I feel like there is a formula for this...
    $endgroup$
    – Embodiment of Ignorance
    Mar 15 at 18:10










  • $begingroup$
    Something to do with beta binomials maybe, but it might be longer to write that out
    $endgroup$
    – Expired Data
    Mar 15 at 18:13










  • $begingroup$
    depends on the language; R and Mathematica might be able to do it efficiently.
    $endgroup$
    – Giuseppe
    Mar 15 at 20:45















$begingroup$
I feel like there is a formula for this...
$endgroup$
– Embodiment of Ignorance
Mar 15 at 18:10




$begingroup$
I feel like there is a formula for this...
$endgroup$
– Embodiment of Ignorance
Mar 15 at 18:10












$begingroup$
Something to do with beta binomials maybe, but it might be longer to write that out
$endgroup$
– Expired Data
Mar 15 at 18:13




$begingroup$
Something to do with beta binomials maybe, but it might be longer to write that out
$endgroup$
– Expired Data
Mar 15 at 18:13












$begingroup$
depends on the language; R and Mathematica might be able to do it efficiently.
$endgroup$
– Giuseppe
Mar 15 at 20:45




$begingroup$
depends on the language; R and Mathematica might be able to do it efficiently.
$endgroup$
– Giuseppe
Mar 15 at 20:45










2 Answers
2






active

oldest

votes


















6












$begingroup$

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





share|improve this answer











$endgroup$












  • $begingroup$
    I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
    $endgroup$
    – Expired Data
    Mar 15 at 20:54


















0












$begingroup$


Wolfram Language (Mathematica), 133 bytes



Length@Select[#2/#&@@@(r=Nest[Sort/@Flatten[Table[k,0+#,⌈#/1,2⌉,k,6]&/@Join[#,Reverse/@#],2]&,1,1,x]),#>=y&]/Length@r



By using N[F,2],the output should print 2 decimal digits but TIO prints more...



Try it online!






share|improve this answer











$endgroup$












    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "200"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181551%2fp%25c3%25b3lya-urn-flip-and-roll%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6












    $begingroup$

    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





    share|improve this answer











    $endgroup$












    • $begingroup$
      I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
      $endgroup$
      – Expired Data
      Mar 15 at 20:54















    6












    $begingroup$

    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





    share|improve this answer











    $endgroup$












    • $begingroup$
      I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
      $endgroup$
      – Expired Data
      Mar 15 at 20:54













    6












    6








    6





    $begingroup$

    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





    share|improve this answer











    $endgroup$



    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






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 16 at 11:41

























    answered Mar 15 at 17:14









    ArnauldArnauld

    79.5k796330




    79.5k796330











    • $begingroup$
      I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
      $endgroup$
      – Expired Data
      Mar 15 at 20:54
















    • $begingroup$
      I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
      $endgroup$
      – Expired Data
      Mar 15 at 20:54















    $begingroup$
    I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
    $endgroup$
    – Expired Data
    Mar 15 at 20:54




    $begingroup$
    I really like this answer, I found that in order to solve the later test cases I needed to add code to merge the same ratio probabilities. So I'm not surprised it's too slow
    $endgroup$
    – Expired Data
    Mar 15 at 20:54











    0












    $begingroup$


    Wolfram Language (Mathematica), 133 bytes



    Length@Select[#2/#&@@@(r=Nest[Sort/@Flatten[Table[k,0+#,⌈#/1,2⌉,k,6]&/@Join[#,Reverse/@#],2]&,1,1,x]),#>=y&]/Length@r



    By using N[F,2],the output should print 2 decimal digits but TIO prints more...



    Try it online!






    share|improve this answer











    $endgroup$

















      0












      $begingroup$


      Wolfram Language (Mathematica), 133 bytes



      Length@Select[#2/#&@@@(r=Nest[Sort/@Flatten[Table[k,0+#,⌈#/1,2⌉,k,6]&/@Join[#,Reverse/@#],2]&,1,1,x]),#>=y&]/Length@r



      By using N[F,2],the output should print 2 decimal digits but TIO prints more...



      Try it online!






      share|improve this answer











      $endgroup$















        0












        0








        0





        $begingroup$


        Wolfram Language (Mathematica), 133 bytes



        Length@Select[#2/#&@@@(r=Nest[Sort/@Flatten[Table[k,0+#,⌈#/1,2⌉,k,6]&/@Join[#,Reverse/@#],2]&,1,1,x]),#>=y&]/Length@r



        By using N[F,2],the output should print 2 decimal digits but TIO prints more...



        Try it online!






        share|improve this answer











        $endgroup$




        Wolfram Language (Mathematica), 133 bytes



        Length@Select[#2/#&@@@(r=Nest[Sort/@Flatten[Table[k,0+#,⌈#/1,2⌉,k,6]&/@Join[#,Reverse/@#],2]&,1,1,x]),#>=y&]/Length@r



        By using N[F,2],the output should print 2 decimal digits but TIO prints more...



        Try it online!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 17 at 3:47

























        answered Mar 17 at 3:40









        J42161217J42161217

        13.4k21252




        13.4k21252



























            draft saved

            draft discarded
















































            If this is an answer to a challenge…



            • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


            • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
              Explanations of your answer make it more interesting to read and are very much encouraged.


            • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


            More generally…



            • …Please make sure to answer the question and provide sufficient detail.


            • …Avoid asking for help, clarification or responding to other answers (use comments instead).




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181551%2fp%25c3%25b3lya-urn-flip-and-roll%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Solar Wings Breeze Design and development Specifications (Breeze) References Navigation menu1368-485X"Hang glider: Breeze (Solar Wings)"e

            Kathakali Contents Etymology and nomenclature History Repertoire Songs and musical instruments Traditional plays Styles: Sampradayam Training centers and awards Relationship to other dance forms See also Notes References External links Navigation menueThe Illustrated Encyclopedia of Hinduism: A-MSouth Asian Folklore: An EncyclopediaRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to Play10.1353/atj.2005.0004The Illustrated Encyclopedia of Hinduism: A-MEncyclopedia of HinduismKathakali Dance-drama: Where Gods and Demons Come to PlaySonic Liturgy: Ritual and Music in Hindu Tradition"The Mirror of Gesture"Kathakali Dance-drama: Where Gods and Demons Come to Play"Kathakali"Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceMedieval Indian Literature: An AnthologyThe Oxford Companion to Indian TheatreSouth Asian Folklore: An Encyclopedia : Afghanistan, Bangladesh, India, Nepal, Pakistan, Sri LankaThe Rise of Performance Studies: Rethinking Richard Schechner's Broad SpectrumIndian Theatre: Traditions of PerformanceModern Asian Theatre and Performance 1900-2000Critical Theory and PerformanceBetween Theater and AnthropologyKathakali603847011Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceBetween Theater and AnthropologyBetween Theater and AnthropologyNambeesan Smaraka AwardsArchivedThe Cambridge Guide to TheatreRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeThe Garland Encyclopedia of World Music: South Asia : the Indian subcontinentThe Ethos of Noh: Actors and Their Art10.2307/1145740By Means of Performance: Intercultural Studies of Theatre and Ritual10.1017/s204912550000100xReconceiving the Renaissance: A Critical ReaderPerformance TheoryListening to Theatre: The Aural Dimension of Beijing Opera10.2307/1146013Kathakali: The Art of the Non-WorldlyOn KathakaliKathakali, the dance theatreThe Kathakali Complex: Performance & StructureKathakali Dance-Drama: Where Gods and Demons Come to Play10.1093/obo/9780195399318-0071Drama and Ritual of Early Hinduism"In the Shadow of Hollywood Orientalism: Authentic East Indian Dancing"10.1080/08949460490274013Sanskrit Play Production in Ancient IndiaIndian Music: History and StructureBharata, the Nāṭyaśāstra233639306Table of Contents2238067286469807Dance In Indian Painting10.2307/32047833204783Kathakali Dance-Theatre: A Visual Narrative of Sacred Indian MimeIndian Classical Dance: The Renaissance and BeyondKathakali: an indigenous art-form of Keralaeee

            Method to test if a number is a perfect power? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Detecting perfect squares faster than by extracting square rooteffective way to get the integer sequence A181392 from oeisA rarely mentioned fact about perfect powersHow many numbers such $n$ are there that $n<100,lfloorsqrtn rfloor mid n$Check perfect squareness by modulo division against multiple basesFor what pair of integers $(a,b)$ is $3^a + 7^b$ a perfect square.Do there exist any positive integers $n$ such that $lfloore^nrfloor$ is a perfect power? What is the probability that one exists?finding perfect power factors of an integerProve that the sequence contains a perfect square for any natural number $m $ in the domain of $f$ .Counting Perfect Powers