A Program in Basic of Ehrenfest's Dog-Flea Problem

00010 ! The dog flea problem                                                    
00020                                                                           
00030 ! **********************************************************************  
00040 ! This program prints the result on a file called 'DATA1'.             *  
00050 ! The file is created anew, and any other file of this name in the     *  
00060 ! file type 'WDATA' will be erased. To get a calcomp plot the file     *  
00070 ! should be 'get'ed in a topdraw program and run normally.             *  
00080 ! **********************************************************************  
00090                                                                           
00100 dim c(400)                                                                
00110 for i= 1 to 100                                                           
00120 c(i)=0                                                                    
00130 next i                                                                    
00140 D$="          "                                                           
00150 for i = 1 to 10                                                           
00160 A$=A$+D$                                                                  
00170 next i                                                                    
00180 a$=str$(A$,1,66)                                                          
00185 print                                                                     
00186 print                                                                     
00187 print                                                                     
00190 print "WARNING      This program will create a file called 'DATA1' , and" 
00200 print "*******      will erase any previous file of the same name"        
00205 print                                                                     
00210 print "             Do you want to run it ? (Yes/No)"                     
00220 input qu$                                                                 
00225 print                                                                     
00226 print                                                                     
00230 if qu$ <> "y" and qu$ <> "Y" and qu$ <> "yes" and qu$ <> "YES"            
00240 goto 600                                                                  
00250 endif                                                                     
00260 OPEN #3 , "DATA1" , OUTPUT                                                
00270 print "Number of times"                                                   
00280 input no                                                                  
00290 ha=0                                                                      
00300 a=300                                                                     
00310 b=0                                                                       
00320 for j= 1 to no                                                            
00330 randomize                                                                 
00340 r=int(rnd*300)                                                            
00350 if c(r)=0                                                                 
00360 c(r)=1                                                                    
00370 a=a-1                                                                     
00380 b=b+1                                                                     
00390 else                                                                      
00400 c(r)=0                                                                    
00410 a=a+1                                                                     
00420 b=b-1                                                                     
00430 endif                                                                     
00440 z=abs(a-b)                                                                
00450 ha=ha+1                                                                   
00460 pp$ = value$(z)                                                           
00470 if len(pp$) < 3                                                           
00480 pp$ = " "+pp$                                                             
00490 goto 470                                                                  
00500 endif                                                                     
00510 qq$=value$(ha)                                                            
00520 if len(qq$) < 3                                                           
00530 qq$ = " "+qq$                                                             
00540 goto 520                                                                  
00550 endif                                                                     
00560 prt$= "    "+qq$+"    "+pp$+a$                                            
00570 print #3,prt$                                                             
00580 next j                                                                    
00590 close #3                                                                  
00600 end                                                                       

previous page

next page for a view of the output

return to lecture notes page