How to resolve the algorithm Bulls and cows step by step in the TUSCRIPT programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bulls and cows step by step in the TUSCRIPT programming language
Table of Contents
Problem Statement
Bulls and Cows is an old game played with pencil and paper that was later implemented using computers.
Create a four digit random number from the digits 1 to 9, without duplication. The program should:
The score is computed as:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bulls and cows step by step in the TUSCRIPT programming language
Source code in the tuscript programming language
$$ MODE tuscript
SET nr1=RANDOM_NUMBERS (1,9,1)
LOOP
SET nr2=RANDOM_NUMBERS (1,9,1)
IF (nr2!=nr1) EXIT
ENDLOOP
LOOP
SET nr3=RANDOM_NUMBERS (1,9,1)
IF (nr3!=nr1,nr2) EXIT
ENDLOOP
LOOP
SET nr4=RANDOM_NUMBERS (1,9,1)
IF (nr4!=nr1,nr2,nr3) EXIT
ENDLOOP
SET nr=JOIN(nr1,"'",nr2,nr3,nr4), limit=10
LOOP r=1,limit
SET bulls=cows=0
ASK "round {r} insert a number":guessnr=""
SET length=LENGTH(guessnr), checknr=STRINGS (guessnr,":>/:")
LOOP n=nr,y=checknr
IF (length!=4) THEN
PRINT "4-letter digit required"
EXIT
ELSEIF (n==y) THEN
SET bulls=bulls+1
ELSEIF (nr.ct.":{y}:") THEN
SET cows=cows+1
ENDIF
ENDLOOP
PRINT "bulls=",bulls," cows=",cows
IF (bulls==4) THEN
PRINT "BINGO"
EXIT
ELSEIF (r==limit) THEN
PRINT "BETTER NEXT TIME"
EXIT
ENDIF
ENDLOOP
You may also check:How to resolve the algorithm Animation step by step in the Maple programming language
You may also check:How to resolve the algorithm Find the missing permutation step by step in the Rust programming language
You may also check:How to resolve the algorithm Parallel brute force step by step in the BaCon programming language
You may also check:How to resolve the algorithm Create a file step by step in the Factor programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Batch File programming language