Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6997595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:18:12+00:00 2026-05-27T20:18:12+00:00

******Last news**** I’ve posted the same question in Math.StackExchange and got a really interesting

  • 0

******Last news****

I’ve posted the same question in Math.StackExchange and got a really interesting answer on how to do this recursively; I have no experience on using matrixes in php neither with recursive calls. Could you please give me a hint on how to code in PHP what he said?

https://math.stackexchange.com/questions/92942/applying-a-math-formula-in-a-more-elegant-way-maybe-a-recursive-call-would-do-t


This could appear a little bit complex at first sight but afterall there’s nothing special.

We are in a poker touranment, there are ‘n’ players, each one has a stack of chips. There are only ‘p’ places to be paid at the end of the tournament.

We want to apply a math formula to convert the actual players’ stacks into money.
So we call ‘equity’ the probability of each player to finish the tournament in each paid place.

I’ll hypothesize there are 4 players (P1,P2,P3,P4) and 3 paid places:

Equity on 1st place is:

$eq1_1 = ($P1_stack / $total_chips);
$eq2_1 = ($P2_stack / $total_chips);
$eq3_1 = ($P3_stack / $total_chips);
$eq4_1 = ($P4_stack / $total_chips);

Equity on 2nd place:

To calculate the equity of each player on 2nd place we have to hypothesize that each one of the remanent players has won the first prize, subtract his(the winner’s) stack from the total chips, divide the player 2 chips by the remanent chips, and multiply this number by the probability(equity on 1st prize of the player who won the 1st prize). I know, brains’ explosions have been reported here.

//-if P2 wins the tornament
$eq1_2 = $eq2_1*($P1_stack/($total_chips-$P2_stack));
//-if P3 wins the tornament
$eq1_2 = $eq1_2 + $eq3_1*($P1_stack/($total_chips-$P3_stack));
//-if P4 wins the tornament
$eq1_2 = $eq1_2 + $eq4_1*($P1_stack/($total_chips-$P4_stack));

if there would have been more players the cycle should have continued.

Equity on 3rd place

If your brain hasn’t exploded yet, it will after you’ll read this :p
To calculate P1 equity on 3rd place we have to:
1) Subtract the winner AND the second winner stacks from the total chips.
2) Subtract P1 stack from the number we got. (Remainingstack)
3) Calculate the equity of the second winner on second place after a winner has been hypothesized.
4) Multiply the number we got (3)
(P1_stack/ Remainingstack)Equity of the winner on 1st place.

I’ve written a working code so far but it works only if there are 3 paid placed. I’d like to modify it to get a more elegant and versatile way to get equity even if the paid places are more than 3.

This is my code: http://codepad.org/Q62l2wfv

I’m not an expert coder but maybe by doing it with a recursive call it should be faster and equity on 4th, 5th, 6th place can be calculated with no difficulties.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:18:13+00:00Added an answer on May 27, 2026 at 8:18 pm

    I’ve answered that question here:

    https://stackoverflow.com/a/8663431/815724

    For completeness I will reproduce that answer:

    Here you go.

    I place this code into the public domain.

    # Function to make an array of 'width' zeros
    function makerow($width){
     $row=array();
     for($x=0;$x<$width;$x++){
       $row[$x]=0;
     }
     return $row;
    }
    
    # Function to make a width*height matrix
    function makematrix($width,$height){
     $matrix=array();
     for($y=0;$y<$height;$y++){
      $matrix[$y]=array();
      for($x=0;$x<$width;$x++){
       $matrix[$y][$x]=0;
      }
     }
     return $matrix;
    }
    
    # Adds one matrix to another
    function matrixadd(&$matrixdest,&$matrixsrc){
     for($i=0;$i<count($matrixdest);$i++){
      for($j=0;$j<count($matrixdest[$i]);$j++){
       $matrixdest[$i][$j]+=$matrixsrc[$i][$j];
      }
     }
    }
    
    # Multiplies a matrix by a scalar
    function matrixmultiply(&$matrix,$scalar){
     for($i=0;$i<count($matrix);$i++){
      for($j=0;$j<count($matrix[$i]);$j++){
       $matrix[$i][$j]*=$scalar;
      }
     }
    }
    
    # Calculates the equity of each place. Rows indicate players;
    # columns indicate places (0 is 1st place, 1 is second, and so on)
    function equitymatrix(&$stacks){
     # If there's only one stack it's easy, one player, thus one place
     if(count($stacks)==1){
      return array(array(1));
     }  
     # Calculate the total of all stacks
     $totalStacks=0;
     for($i=0;$i<count($stacks);$i++){
      $totalStacks+=$stacks[$i];
     }
     # Calculate the probabilities of each player getting first place
     $probabilities=array();
     for($i=0;$i<count($stacks);$i++){
      $probabilities[$i]=$stacks[$i]*1.0/$totalStacks;
     }
     $subequities=array();
     for($i=0;$i<count($stacks);$i++){
      $substacks=array();
      # Assume that player i would be in first place
      # Create a new array with i's stack removed
      for($j=0;$j<count($stacks);$j++){
       if($j!=$i){
        array_push($substacks,$stacks[$j]);
       }
      }
      # Find the subequity of the remaining players
      $subequities[$i]=equitymatrix($substacks);
      for($j=0;$j<count($subequities[$i]);$j++){
       array_splice($subequities[$i][$j],0,0,0);
      }
      # Add player i back
      $newrow=makerow(count($stacks));
      $newrow[0]=1;
      array_splice($subequities[$i],$i,0,array($newrow));
     }
     $equities=makematrix(count($stacks),count($stacks));
     for($i=0;$i<count($stacks);$i++){
      # Multiply the probabilities
      matrixmultiply($subequities[$i],$probabilities[$i]);
      # Add the subequity
      matrixadd($equities,$subequities[$i]);
     }
     return $equities;
    }
    

    Example:

    $mystacks=array(10,40,30,20);
    print_r(equitymatrix($mystacks));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have there is a table showing the last 10 news. But when I
I have this code set up and everything works except the last line for
I have a news portal. For this portal I have a database with a
i have created view , in short it display last 5 news title and
I have written this code to loop through the last 6 posts and display
I have this javascript code: function newsOverview() { $(.list-news li:gt(3)).hide(); $(.box-news .btn-1).on('click', function(e){ e.preventDefault;
I have this code for a news feed and it's combined with a code
I Have two tables. I want to show one last news in each related
This XML file contained archived news stories for all of last year. I was
Last night I tried to put together something that I have had working since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.