program turistid; uses crt; label uuesti; var kohvik, protsent, i,turistide_arv:integer; uturist1, uturist2, vturist1, vturist2:integer; turist1,turist2,r,t:integer; begin randomize; turistide_arv:=10000; kohvik:=0;{loendab kohvikusse joudvaid turiste} for i:=1 to turistide_arv do begin {turist1 paremale,turist2 otse,sel juhul on nende kohtumise P v2ga v2ike} vturist1:=0; vturist2:=0; turist1:=2; turist2:=5; uuesti: r:=random(4); {turist1} t:=random(4); {turist2} {Kui turistid asuvad skeemi vasakul voi paremal serval} if ((turist1=5) or (turist1=9) or (turist1=13) or (turist1=17)) and (r=1) then goto uuesti; if ((turist1=4) or (turist1=8) or (turist1=12) or (turist1=16)) and (r=0) then goto uuesti; if ((turist2=5) or (turist2=9) or (turist2=13) or (turist2=17)) and (t=1) then goto uuesti; if ((turist2=4) or (turist2=8) or (turist2=12) or (turist2=16)) and (t=0) then goto uuesti; {Skeemi ylemine ja alumine osa} if ((turist1=17) or (turist1=18) or (turist1=19) or (turist1=20)) and (r=2) then goto uuesti; if ((turist1=2) or (turist1=3) or (turist1=4)) and (r=3) then goto uuesti; if ((turist2=17) or (turist2=18) or (turist2=19) or (turist2=20)) and (t=2) then goto uuesti; if ((turist2=2) or (turist2=3) or (turist2=4)) and (t=3) then goto uuesti; if r=0 then uturist1:=turist1+1; if r=1 then uturist1:=turist1-1; if r=2 then uturist1:=turist1+4; if r=3 then uturist1:=turist1-4; if t=0 then uturist2:=turist2+1; if t=1 then uturist2:=turist2-1; if t=2 then uturist2:=turist2+4; if t=3 then uturist2:=turist2-4; {Et turistid ei laheks skeemist valja.Leian turisti uue asukoha.} if (uturist1<>turist1) and (uturist1<21) and (uturist1>0) and (uturist2<>turist2) and (uturist2<21) and (uturist2>0) then begin vturist1:=turist1; turist1:=uturist1; vturist2:=turist2; turist2:=uturist2; end; { writeln(turist1, ' ', turist2); delay(100); } {Kui turistid pole veel kohvikusse joudnud:} if (turist1<>11) and ((turist1<>1) or (turist1=0)) and(turist2<>11) and ((turist2<>1) or (turist2=0)) then goto uuesti; {Turistid jouavad kohvikusse:} if (turist1=11 )and (turist2=11)then kohvik:=kohvik+1; end; protsent:=round((kohvik/turistide_arv)*100); writeln('Need kaks turisti jäuavad korraga kohvikusse ',kohvik,' korral ',turistide_arv,'-st, seega ',protsent,'%.'); readln; end.