©
serviceprofessionalgmbh
The computer produces a number of 3 to 9 digits (default is 4 digits) which has to be guessed by the player. The player
enters his guess. The computer returns how many numbers are located at the correct digit (corrects digits marked by x)
and how many are correct but in the wrong place (each one indicated by o).
xxo would mean: 3 numbers are correct, 2 of them are located in the right place.
/* REXX
*/
arg anz
if anz < 3 ! anz > 9 then anz = 4
do forever
v=0;zahl0="";ro=0;rz=0
do anz /* random() kann 999999999 nicht liefert, deshalb byteweise */
zahl0=zahl0 !! random(0,9)
end
do until v >= 10 ! zahl2 = zahl0
zahl1=zahl0
hinweis=copies("x",ro) !! copies("o",rz)
hinweis=left(hinweis,anz,"-")
say hinweis v+1'. Eingabe:'
parse upper external zahl2
do while datatype(zahl2) = char ! zahl2 > copies("9",length(zahl0))
say 'Eingabe liegt nicht im erlaubten Bereich, wiederholen:'
parse external zahl2
end
zahl2=right(zahl2,length(zahl0),0)
v=v+1
ro=0
rz=0
if zahl1=zahl2 then do /* richtig */
select
when v < 2 then e = 'Zufallstreffer'
when v < 3 then e = 'Spitzenklasse'
when v < 5 then e = 'Super'
when v < 8 then e = 'Gut'
otherwise e = 'Koennte besser sein'
end
say e '- im' v'. Versuch. Gratulation, Sie haben gewonnen'
end
else do /* falsch */
do x=1 to length(zahl1)
if substr(zahl2,x,1) = substr(zahl1,x,1) then do
ro=ro+1
zahl1=overlay('a',zahl1,x,1)
zahl2=overlay('b',zahl2,x,1)
end
end
do x=1 to length(zahl1)
do y=1 to length(zahl1)
if substr(zahl1,x,1)=substr(zahl2,y,1) then do
zahl1=overlay('a',zahl1,x,1)
zahl2=overlay('b',zahl2,y,1)
rz=rz+1
end
end
end
if v > 9 then say 'Hirni - erst denken dann eingeben'
end
end
ant=''
do while ant ^= 'J' & ant ^= 'N'
say 'Ein neues Spiel (J/N):'
pull ant
end
if ant = 'N' then leave
end
exit
back to Fun & More