The posts in this thread are from Rosetta Code Challenges.
You are free to post improvements.
Better IMHO is less LOC (Lines Of Code) but try to hold off on using so many colons on a line: none is perfect, one or 2 reasonable, 10 ridiculous! = too much)
_____________________________________________________________________________________________
Ken was asking about this today.
Bulls and cows: http://rosettacode.org/wiki/Bulls_and_cows
You are free to post improvements.
Better IMHO is less LOC (Lines Of Code) but try to hold off on using so many colons on a line: none is perfect, one or 2 reasonable, 10 ridiculous! = too much)
_____________________________________________________________________________________________
Ken was asking about this today.
Bulls and cows: http://rosettacode.org/wiki/Bulls_and_cows
Code: (Select All)
_Title "Bulls and Cows" ' found at Rosetta for Qbasic, copy 2019-01-31
'challenge is to develope AI player for this game
DefInt A-Z
Dim secret As String
Dim guess As String
Dim c As String
Dim bulls, cows, guesses, i
Randomize Timer
Do While Len(secret) < 4
c = Chr$(Int(Rnd * 10) + 48)
If InStr(secret, c) = 0 Then secret = secret + c
Loop
guesses = 0
Do
Input "Guess a 4-digit number with no duplicate digits: "; guess
guess = LTrim$(RTrim$(guess))
If Len(guess) = 0 Then Exit Do
If Len(guess) <> 4 Or Val(guess) = 0 Then
Print "** You should enter 4 numeric digits!"
GoTo looper
End If
bulls = 0: cows = 0: guesses = guesses + 1
For i = 1 To 4
c = Mid$(secret, i, 1)
If Mid$(guess, i, 1) = c Then
bulls = bulls + 1
ElseIf InStr(guess, c) Then
cows = cows + 1
End If
Next i
Print bulls; " bulls, "; cows; " cows"
If guess = secret Then
Print "You won after "; guesses; " guesses!"
Exit Do
End If
looper:
Loop
b = b + ...