Welcome, Guest |
You have to register before you can post on our site.
|
Latest Threads |
[split] Lines of Code
Forum: General Discussion
Last Post: mdijkens
37 minutes ago
» Replies: 12
» Views: 80
|
_CONSOLEINPUT is blocking
Forum: General Discussion
Last Post: mdijkens
1 hour ago
» Replies: 12
» Views: 170
|
[split] BAM and _IIF with...
Forum: QBJS, BAM, and Other BASICs
Last Post: CharlieJV
7 hours ago
» Replies: 8
» Views: 49
|
Who wants to PLAY?
Forum: QBJS, BAM, and Other BASICs
Last Post: dbox
10 hours ago
» Replies: 17
» Views: 294
|
QBJS v0.9.0 - Release
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
11 hours ago
» Replies: 23
» Views: 415
|
Curious if I am thinking ...
Forum: Help Me!
Last Post: bplus
11 hours ago
» Replies: 27
» Views: 606
|
ADPCM compression
Forum: Petr
Last Post: Petr
Yesterday, 09:37 PM
» Replies: 1
» Views: 58
|
Aloha from Maui guys.
Forum: General Discussion
Last Post: Pete
Yesterday, 07:33 PM
» Replies: 18
» Views: 519
|
Qix line monster
Forum: Programs
Last Post: bplus
Yesterday, 05:38 PM
» Replies: 1
» Views: 56
|
Trojan infection !
Forum: Help Me!
Last Post: PhilOfPerth
Yesterday, 09:14 AM
» Replies: 4
» Views: 107
|
|
|
Rosetta Code Challenges |
Posted by: bplus - 04-26-2022, 09:17 PM - Forum: bplus
- Replies (15)
|
|
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
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
|
|
|
|