How to resolve the algorithm 100 prisoners step by step in the FOCAL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 100 prisoners step by step in the FOCAL programming language
Table of Contents
Problem Statement
Show and compare the computed probabilities of success for the two strategies, here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 100 prisoners step by step in the FOCAL programming language
Source code in the focal programming language
01.10 T %5.02," RANDOM";S CU=0
01.20 F Z=1,2000;D 5;S CU=CU+SU
01.30 T CU/20,!,"OPTIMAL";S CU=0
01.40 F Z=1,2000;D 6;S CU=CU+SU
01.50 T CU/20,!
01.60 Q
02.01 C-- PUT CARDS IN RANDOM DRAWERS
02.10 F X=1,100;S D(X)=X
02.20 F X=1,99;D 2.3;S B=D(X);S D(X)=D(A);S D(A)=B
02.30 D 2.4;S A=X+FITR(A*(101-X))
02.40 S A=FABS(FRAN()*10);S A=A-FITR(A)
03.01 C-- PRISONER X TRIES UP TO 50 RANDOM DRAWERS
03.10 S TR=50;S SU=0
03.20 D 2.4;I (X-D(A))3.3,3.4,3.3
03.30 S TR=TR-1;I (TR),3.5,3.2
03.40 S SU=1;R
03.50 S SU=0
04.01 C-- PRISONER X TRIES OPTIMAL METHOD
04.10 S TR=50;S SU=0;S A=X
04.20 I (X-D(A))4.3,4.4,4.3
04.30 S TR=TR-1;S A=D(A);I (TR),4.5,4.2
04.40 S SU=1;R
04.50 S SU=0
05.01 C-- PRISONERS TRY RANDOM METHOD UNTIL ONE FAILS
05.10 D 2;S X=1
05.20 I (X-101)5.3,5.4
05.30 D 3;S X=X+1;I (SU),5.4,5.2
05.40 R
06.01 C-- PRISONERS TRY OPTIMAL METHOD UNTIL ONE FAILS
06.10 D 2;S X=1
06.20 I (X-101)6.3,6.4
06.30 D 4;S X=X+1;I (SU),6.4,6.2
06.40 R
You may also check:How to resolve the algorithm Tokenize a string step by step in the Plain English programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sleep step by step in the PowerShell programming language
You may also check:How to resolve the algorithm First class environments step by step in the Wren programming language