Post Reply 
Ehrenfest's urn
12-30-2021, 05:28 AM
Post: #4
RE: Ehrenfest's urn
(12-29-2021 11:53 PM)zahi48g Wrote:  it does not try to remove L2(2) from L2 but n from L2 .

With SUPPRESS(L2,n) you are removing from L2 the element at the nth position, so if L2={2} then SUPRESS(L2,2) will fail because there is only one element in the list. The correct instruction to remove 2 from the list is SUPPRESS(L2,POS(L2,2))) which will remove 2 from the list whatever it’s position in the list.

(12-29-2021 11:53 PM)zahi48g Wrote:  If you get these results , could copy and paste you code ?

Here is a working code, I’ve added the number of elements in the urns as a parameter of the program so you can test with more than two:

Code:
#pragma mode( separator(.,;) integer(h32) )

EXPORT EHRENFEST1(N)
BEGIN
 LOCAL n,p,K;
 INPUT(p);
 L1:=MAKELIST(I,I,1,N);
 L2:={};
 FOR K FROM 1 TO p DO
  n:=RANDINT(1,N);
  IF POS(L1,n) THEN
   L1:=SUPPRESS(L1,POS(L1,n));
   L2(0):=n;
  ELSE
   L2:=SUPPRESS(L2,POS(L2,n));
   L1(0):=n;
  END;
 END;
 PRINT(SORT(L1));
 PRINT(SORT(L2));
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Ehrenfest's urn - zahi48g - 12-29-2021, 10:16 PM
RE: Ehrenfest's urn - toml_12953 - 12-29-2021, 11:11 PM
RE: Ehrenfest's urn - zahi48g - 12-29-2021, 11:53 PM
RE: Ehrenfest's urn - Didier Lachieze - 12-30-2021 05:28 AM
RE: Ehrenfest's urn - John Keith - 12-30-2021, 10:30 PM
RE: Ehrenfest's urn - zahi48g - 01-03-2022, 11:10 PM
RE: Ehrenfest's urn - toml_12953 - 01-04-2022, 02:09 AM



User(s) browsing this thread: 1 Guest(s)