LOGO-L> Randomly Chosen Balls

Hello everyone,

I hope you'll have a good week-end and this little problem may be brings

you some fun.

It has a gas behaviour background. Specialists will describe all this

better, I'll just say, that the suggested program describes the

Ehrenfest model.

Given two jugs. One initially is filled with the numbered (1 through n)

bals, the other is empty. There is also a box with numbered (1--n)

tickets. One randomly choose the ticket, reads it's number and puts it

back into the box. Then he takes a ball with that number from one jug

and puts it into the other. He repeats this actions many times.

The question is to describe the quantity change of the balls in both

jugs.

It might be solved in Logo with the using just one list for balls. The

balls in one jug are marked with 1, in the other -- with -1.

Diagrams are drawn after 50th, 100th, 150th, etc., balls are chosen.

This is my suggestion:

-----------------------

to balls.main

pr [please, give the number of balls]

make "n rw

make "a []

balls.form

balls.process 1

end

to balls.form

; initial "filling" of the jug

repeat :n [make "a lput 1 :a]

end

to balls.process :ncount

; the ball with the chosen number changes it's jug.

invert 1+randm :n

if (remainder :ncount 50) = 0 ~

[balls.diagramma (:n+balls.summa)/2 (:n-balls.summa)/2]

balls.process :ncount+1

end

to balls.summa

make "s 0

repeat :n [make "s :s+item repcount :a]

op :s

end

to invert :i

repeat :i-1[make "a bf lput first :a :a]

make "a bf lput -1*first :a :a

repeat :n-:i[make "a bf lput first :a :a]

end

to balls.diagramma :x :y

cs

ht

pu setxy -30 0 setpensize [15 15] setpc [255 0 0]

pd fd :x/:n*200

pu setxy 30 0 setpensize [15 15] setpc [0 0 255]

pd fd :y/:n*200

end

--------------------------------

I know at least one person, who will do it much better. :-)

I'm curious to know -- how?

Regards,

Olga.

______________________________________________________

Get Your Private, Free Email at http://www.*-*-*.com/

---------------------------------------------------------------