Bulls and cows/Player: Difference between revisions

m
→‎{{header|REXX}}: added better checks for guesses that contain a zero digit.
m (→‎{{header|REXX}}: added better checks for guesses that contain a zero digit.)
Line 2,512:
do tries=1 until #()<2 | bull==4; say
call prompter
do ?=L1234 to H 9876 /*traipse through the whole list. */
if @.?==. then iterate /*was this choice already eliminated ? */
call bull# ?,g /*obtain the bulls and cows count. */
Line 2,529:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
#: #=0; do k=L1234 to H9876; if @.k==. then iterate; #=# + 1; g=k; end; return #
gen@: @.=.; L=1234; H=9876; do j=L1234 to H9876; if genOK\rep() & pos(0, j)==0 then @.j=j; end; return
genOKrep: do k=1 for 3; if pos(0substr(j, k, 1), j, k+1)\==0 then return 01; end; return \rep()0
serr: say; say pad '***error*** ' ! arg(1); return
rep: do k=1 for 3; if pos(substr(j,k,1),j,k+1)\==0 then return 1; end; return 0
serr: say; say pad '***error*** ' ! arg(1); return
/*──────────────────────────────────────────────────────────────────────────────────────*/
bull#: parse arg n,q; L=length(n); bulls=0; cows=0 /*initialize some vars.*/
Line 2,550 ⟶ 2,549:
do forever; say
say pad "How many bulls and cows were guessed with " g '? [─── or QUIT]'
pull x 1 bull cow _ . /*PULL capitalizes the arguments.*/
if abbrev('QUIT', x, 1) then exit /*the user wants to quit playing.*/
select
when bull == '' then != "no numbers were entered."
when cow == '' then != "not enough numbers were entered."
when _\=='' words(x) > 2 then != "too many numbers entered: " x
when \datatype(bull, 'W') then != "1st number (bulls) not an integer: " bull
when \datatype(cow , 'W') then != "2nd number (cows) not an integer: " cow
Line 2,564 ⟶ 2,563:
end /*select*/
if !\=='' then do; call serr; iterate; end /*prompt the user and try again. */
bull=bull / 1; cow=cow / 1; return /*normalize bulls & cows numbers.*/
end /*forever*/</lang> <br><br>
 
=={{header|Ring}}==