Binomial Distribution

Author(s): P. R. Scott
Publication: Timex Sinclair User
Pub Details: Timex Sinclair User n3 (Volume 1, Issue 3)
Date: August 1983
Pages: 38
Ball bouncing down through a field of pegs
Ball bouncing down through a field of pegs

BINOMIAL DISTRIBUTION might be the first of a new style of program. P R Scott, who submitted it, believes that there are many fundamental scientific principles which could profitably be illustrated on Timex Sinclair machines.

This program for the 16K T/S1000,ZX81 serves to illustrate the principle of binomial distribution. The display shows a ball falling through a triangular matrix of pegs. When the ball hits one of the pegs it rebounds to the left or right, entirely at random.

Its final position is recorded and a further ball produced. The distribution of final positions is the binomial distribution, familiar to most mathematics seniors. You may not know that this characteristic pattern is also of importance in spectral intensities and polymer conformations.

An excellent program, likely to prove of immediate use to teachers and students of mathematics. Graphics notes: 120 — Minus, Four spaces, minus and so on.

  10 DIM A(7)
20 FOR X=1 TO 7
30 LET A(X)=0
40 NEXT X
50 PRINT AT 0,5;"BINOMIAL DISTRIBUTION"
60 PRINT AT 5,15; "▒"
70 PRINT AT 7,14; "▒ ▒"
80 PRINT AT 9,13; "▒ ▒ ▒"
90 PRINT AT 11,12; "▒ ▒ ▒ ▒"
100 PRINT AT 13,11; "▒ ▒ ▒ ▒ ▒"
110 PRINT AT 15,10; "▒ ▒ ▒ ▒ ▒ ▒"
120 PRINT AT 17,9; "- - - -"
130 PRINT AT 18,11; "- - -"
200 PRINT AT 3,15; "O"
210 LET X=15
220 LET Y=3
230 LET XP=X
240 GOSUB 400
250 IF Y=16 THEN GOTO 490
260 LET R=RND
270 IF R < 0.5 THEN LET X=X+1
280 IF R >= 0.5 THEN LET X=X-1
290 GOSUB 400
300 GOTO 230
400 PRINT AT Y,XP; " "
410 LET Y=Y+1
420 PRINT AT Y,X; "O"
430 RETURN
490 PRINT AT 16,X; " "
500 LET Z=(X-7)/2
510 LET A(Z)=A(Z)+1
520 LET P=17
530 IF Z/2=INT (Z/2) THEN LET P=18
540 LET Q=X
550 IF A(Z) >= 10 THEN LET Q=Q-1
560 PRINT AT P,Q; A(Z)
570 IF A(Z)=50 THEN INPUT Z$
580 GOTO 200

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.