Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guess My Number
#10
Program dafindnum.bas guesses unanswered number less or more
by starting from middle of list and comparing odd and even ones separately

Visual:
Code: (Select All)
123456789    
    5
    5
    5 7
  3 5 7
  3 5 7 9
1 3 5 7 9
1 3 567 9
1 3 567 9
1 3 56789
1 3456789
1 3456789
123456789

Won if you guessed less than number before attempt
or lost if you guessed from beginning faster

It is effective if distribution of guesses is normal undulating
however how to evaluate result of integral is still unknown

However experimental program is not optimal
and it is possible to include a step greater than 2

Code: (Select All)
n = 55: Randomize Timer: a = Int(Rnd * (n - 1)) + 1 ' dafindnum.bas
start = Int(1 + n / 2) ' https://qb64phoenix.com/forum/showthread.php?tid=900
Print "n= "; n, "a= "; a: Print: s = 0

For i = 0 To 1: For j = 0 To n / 4

    t = Int(start + j * 2) + i
    If t > n Then 5
    s = s + 1: Print s, t
    If t = a Then 25

    5 t = Int(start - j * 2) + i
    If t < 1 Then 15
    s = s + 1: Print s, t
    If t = a Then 25

15 Next: Next ': Print "NO...": End

25 Print: Print "Step="; s, "Guess="; a, "Max="; n
If s < a Then Print "WIN" Else If s > a Then Print "Lose" Else Print "Draw"
End

Checking 1000 or a dozen thousand showed:
Draw 25% and Lose 37.5% and Win 37.5%

Code: (Select All)
n = 3*10^4: start = Int(1 + n / 2) ' dafindnum99.bas
w = 0: l = 0: d = 0 ' Win Lose Draw

For a = 1 To n: s = 0
    For i = 0 To 1 ' even \ odd
        For j = 0 To n / 4

            t = Int(start + j * 2) + i ' right
            If t > n Then 5
            s = s + 1
            If t = a Then 25

            5 t = Int(start - j * 2) + i ' left
            If t < 1 Then 15
            s = s + 1
            If t = a Then 25

    15 Next: Next ': Print "NO..." : End

    25 Print "Max="; n, "Guess="; a, "Step="; s,
    If s < a Then Print "WIN": w = w + 1 Else If s > a Then Print "Lose": l = l + 1 Else Print "Draw": d = d + 1
Next a: Print: Print "Win= "; w, "Lose= "; l, "Draw= "; d
End

So if a draw is considered a win then algorithm it is effective

[Image: guess22.png]

[Image: guess99.png]

picture: 10 kB
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply


Messages In This Thread
Guess My Number - by SierraKen - 09-18-2022, 11:04 PM
RE: Guess My Number - by PhilOfPerth - 09-18-2022, 11:11 PM
RE: Guess My Number - by bplus - 09-19-2022, 12:25 AM
RE: Guess My Number - by SierraKen - 09-20-2022, 09:23 PM
RE: Guess My Number - by DANILIN - 09-25-2022, 12:47 PM
RE: Guess My Number - by mnrvovrfc - 09-25-2022, 05:21 PM
RE: Guess My Number - by SierraKen - 09-25-2022, 08:21 PM
RE: Guess My Number - by mnrvovrfc - 09-26-2022, 05:16 AM
RE: Guess My Number - by SierraKen - 09-25-2022, 08:24 PM
RE: Guess My Number - by DANILIN - 11-07-2022, 10:45 AM
RE: Guess My Number - by DANILIN - 02-23-2023, 02:45 AM
RE: Guess My Number - by Sprezzo - 02-24-2023, 02:33 PM
RE: Guess My Number - by DANILIN - 02-24-2023, 04:22 PM
RE: Guess My Number - by bplus - 02-24-2023, 04:36 PM
RE: Guess My Number - by DANILIN - 02-24-2023, 04:52 PM
RE: Guess My Number - by bplus - 02-24-2023, 05:09 PM
RE: Guess My Number - by DANILIN - 04-04-2023, 08:35 AM
RE: Guess My Number - by SMcNeill - 04-04-2023, 10:58 AM
RE: Guess My Number - by DANILIN - 05-20-2023, 03:36 AM



Users browsing this thread: 4 Guest(s)