Anonymous user
Bulls and cows: Difference between revisions
m
→version 1: changed command and whitespace.
m (added it to the games category.) |
m (→version 1: changed command and whitespace.) |
||
Line 4,077:
<br>and also change the prompt message.
<br>The REXX statement that contains the '''translate''' statement can be removed if repeated digits aren't allowed.
<lang rexx>/*REXX
?=; do until length(?)==4 /*generate a unique
r=random(1, 9) /*change
if pos(r, ?)\==0 then iterate /*don't allow a repeated digit/numeral.
?=? || r /*add random
end /*until length ···
id= '──────── [Bulls & Cows] '
do until bulls==4; say /*play until guessed or enters "QUIT".*/
q=?; L=length(n); bulls=0; cows=0 /*initialize some REXX variables. */▼
bulls=bulls+1; q=overlay(.,q,j) /*bump bull count; disallow for cow*/
▲ say '───── [Bulls & Cows] Please enter a 4-digit guess (with no zeroes) [or Quit]:'
▲ pull n; n=space(n,0); if abbrev('QUIT',n,1) then exit /*Quit ?*/
▲ q=?; L=length(n); bulls=0; cows=0 /*initialize some REXX variables.*/
▲ end /*j*/ /* [↑] bull count───────────────*/
▲ do k=1 for L; _=substr(n,k,1); if pos(_,q)==0 then iterate
say " │ │"▼
▲ say
say " └─────────────────────────────────────────┘"; say▼
▲ if L\==0 & bulls\==4 then say "───── You got" bulls 'bull's(bulls) "and" cows 'cow's(cows)"."
exit /*stick a fork in it, we're all done. */▼
▲ end /*until bulls···*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return '';
▲say; say " ┌─────────────────────────────────────────┐"
▲ say " │ │"
▲ say " │ │"
▲ say " └─────────────────────────────────────────┘"; say
▲exit /*stick a fork in it, we're done.*/
▲s: if arg(1)==1 then return ''; return 's' /*handles plurals.*/</lang>
===Version 2===
|