5 GOSUB 500
10 DIM D(10,4),B(10),C(10),G(10)
15 RANDOMIZE TIMER:PRINT 
17 PRINT "    BULL = CORRECT DIGIT IN THE CORRECT POSITION"
18 PRINT "    COW = CORRECT DIGIT BUT IN THE WRONG POSITION"
20 A=0:goto 200
30 PRINT:PRINT:PRINT "      THINK OF A 5 DIGIT NUMBER AND I WILL TRY TO "
32 PRINT "      GUESS IT WHILE YOU TRY TO GUESS MY NUMBER !!"
35 PRINT "YOUR GUESS";:INPUT N:N=(N+.1)/100000
40 FOR I=0 TO 4:G(I)=INT(10*N):N=10*N-INT(10*N)
41 FOR K=0 TO I-1:IF G(I)=G(K) goto 170
42 NEXT K
43 NEXT I
45 P=4:A=0:GOSUB 300
50 PRINT V"BULL";:IF V<>1 THEN PRINT "S";
55 IF V=5 THEN PRINT " - YOU WIN":clear:goto 20
60 PRINT W-V"COW";:IF W<>V+1 THEN PRINT "S";
65 IF J=0 THEN A=1:goto 200
68 GOSUB 400
70 PRINT " - MY GUESS IS ";
75 FOR I=0 TO 4:PRINT CHR$(D(J,I)+48);:NEXT I
80 PRINT " MY SCORE";:INPUT B(J),C(J):C(J)=C(J)+B(J)
81 IF B(J)>-1 THEN IF B(J)<6 THEN IF C(J)<6 THEN IF C(J)-B(J)>-1 goto 83
82 PRINT " - RIDICULOUS!!";:goto 70
83 IF B(J)=4 THEN IF C(J)=5 goto 82
85 IF B(J)=5 THEN PRINT " - I WIN - MY NUMBER WAS ";:goto 100
90 goto 35
100 FOR I=0 TO 4:PRINT CHR$(D(0,I)+48);:NEXT I
110 clear:goto 20
150 PRINT:PRINT "YOU HAVE GIVEN ME IMPOSSIBLE SCORES - GAME SPOILED":clear:goto 10
170 PRINT "REPEATED DIGITS NOT ALLOWED":goto 35
200 FOR P=0 TO 4
210 D(A,P)=INT(10*RND(1))
220 FOR I=0 TO P-1:IF D(A,I)=D(A,P) goto 210
230 NEXT I
240 NEXT P
250 IF A=0 goto 30
260 J=1:goto 70
300 V=0:W=0
310 FOR I=0 TO P:IF D(A,I)=G(I) THEN V=V+1
320 FOR K=0 TO 4:IF D(A,K)=G(I) THEN W=W+1
330 NEXT K
340 NEXT I
350 RETURN
400 P=0
405 G(P)=D(J,P)
410 FOR I=0 TO P-1:IF G(I)=G(P) goto 430
415 NEXT I
420 FOR A=1 TO J:GOSUB 300
425 IF V<=B(A) THEN IF W<=C(A) THEN IF 4-P>=C(A)-W THEN IF 4-P>=B(A)-V goto 448
430 G(P)=G(P)+3:IF G(P)>9 THEN G(P)=G(P)-10
432 IF P=0 THEN IF G(P)=D(1,0) goto 150
435 IF G(P)<>D(J,P) goto 410
440 P=P-1:IF P<0 THEN goto 150
445 goto 430
448 NEXT A
450 P=P+1:IF P<5 goto 405
455 J=J+1
460 FOR I=0 TO 4:D(J,I)=G(I):NEXT I
465 RETURN
500 PRINT:PRINT:PRINT "      BRADFORD UNIVERSITY BULLS AND COWS GAME"
510 goto 10
999 END
