[VA] SRC #012a - Then and Now: Probability
|
10-17-2022, 03:45 PM
Post: #55
|
|||
|
|||
RE: [VA] SRC #012a - Then and Now: Probability
Here is my code for the HP41, which does not have enough memory for the matrix approach. It only works for S = N-1 and uses that one only has to worry about the paths that increase R in every step, as all other paths do not reach the last row in time. It then uses that the number of ways of reaching the last row is the binomial tree (from each node there are two ways to reach the next row, with the exception of the edges).
As such, its rather trivial. Inspired by Albert and others I was then trying to figure out if there is a way to scale the result for S=N-1 to S=N, S=N+1, etc given that it trends asymptotically to a fixed value. However, I was not able to do so and now it has closed, so apologies for posting my code only now. The code uses that only steps that increase the row can work. It also uses the symmetry between left and right. When walking down the left edge, starting at some point in row y, the first step then always has a probability of 1/4 to go towards the middle. Afterwards all probabilities to go downwards are 2 * 1/6 (one to the left and one to the right) or 1/3. This goes on for the remaining rows x to the last row. The first y = R-3, with R being the total number of rows. (The step from row 1 to 2 is just 1/2 to go to the left, then you have 1/4 to go right down towards the middle, row 3, from which the 1/6 probabilities to go down left and right to row 4 start) x = (R-3) - y For each of these possible vertices the probabilities reach final row are (1/4)^x * (1/3)^y At the end we have to take care of the symmetry and the first step. STO 00......R-3 STO 01......y STO 02...... probability of ending in last row STO 03...... 1/3 (for speed, number entry in 41 is very slow) STO 04...... 1/4 (for speed, number entry in 41 is very slow) Enter into X the number of rows, press R/S LBL "SRC12A" 3 - STO 00 ! R-3 STO 01 ! y LastX 1/x STO 03 ! (1/3) X<>Y y^x STO 02 ! prob P 4 1/x STO 04 ! (1/4) LBL 00 ! loop over y = (R-3) to 0 RCL 03 RCL 01 DECx x<0? GTO 01 ! -> we are done STO 01 y^x RCL 04 RCL 00 RCL 01 - y^x * ST+ 02 GTO 00 LBL 01 RCL 04 RCL 00 y^x ST+ 02 RCL 04 ST* 02 View 02 STOP end Cheers, PeterP |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 12 Guest(s)