Jump to content

I can guess your number in less than 8 times.


Kip
 Share

Recommended Posts

This little program can guess your number (any number between 0 and 100) in less than 8 retries.

You think that's not true? Try it!

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$COUNT = 1
$DIVIDE = 2

MsgBox(0,"Mind Reader","Pick a number between 0 and 100.")

$Form1 = GUICreate("Mind Reader", 451, 125)
$Lower = GUICtrlCreateButton("My number is lower", 64, 72, 121, 25, 0)
$Correct = GUICtrlCreateButton("That's it", 192, 72, 65, 25, 0)
$Higher = GUICtrlCreateButton("My number is higher", 264, 72, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("Is this your number? :", 72, 32, 104, 17)
$Number = GUICtrlCreateLabel("50", 192, 8, 120, 64)
GUICtrlSetFont(-1, 40, 400, 0, "Arial")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        Case $Correct
            MsgBox(0,"Mind Reader","I knew I could guess it."&@CRLF&"I only tried it "&$COUNT&" times!"&@CRLF&@CRLF&"Ok, again. Pick a number between 0 and 100.")
            
            GUICtrlSetData($Number,50)
            $COUNT = 1
            $DIVIDE = 2
            
        Case $Higher
            
            $DIVIDE = $DIVIDE*2
            $Add = 100/$DIVIDE
            
            $Read = GUICtrlRead($Number)
            GUICtrlSetData($Number,Round($Read+$Add))
            $COUNT += 1
            
        Case $Lower
            
            $DIVIDE = $DIVIDE*2
            $Add = 100/$DIVIDE
            
            $Read = GUICtrlRead($Number)
            GUICtrlSetData($Number,Round($Read-$Add))
            $COUNT += 1
            
    EndSwitch
WEnd
Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

This little program can guess your number (any number between 0 and 100) in less than 8 retries.

You think that's not true? Try it!

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$COUNT = 1
$DIVIDE = 2

MsgBox(0,"Mind Reader","Pick a number between 0 and 100.")

$Form1 = GUICreate("Mind Reader", 451, 125)
$Lower = GUICtrlCreateButton("My number is lower", 64, 72, 121, 25, 0)
$Correct = GUICtrlCreateButton("That's it", 192, 72, 65, 25, 0)
$Higher = GUICtrlCreateButton("My number is higher", 264, 72, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("Is this your number? :", 72, 32, 104, 17)
$Number = GUICtrlCreateLabel("50", 192, 8, 120, 64)
GUICtrlSetFont(-1, 40, 400, 0, "Arial")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        Case $Correct
            MsgBox(0,"Mind Reader","I knew I could guess it."&@CRLF&"I only tried it "&$COUNT&" times!"&@CRLF&@CRLF&"Ok, again. Pick a number between 0 and 100.")
            
            GUICtrlSetData($Number,50)
            $COUNT = 1
            $DIVIDE = 2
            
        Case $Higher
            
            $DIVIDE = $DIVIDE*2
            $Add = 100/$DIVIDE
            
            $Read = GUICtrlRead($Number)
            GUICtrlSetData($Number,Floor($Read+$Add))
            $COUNT += 1
            
        Case $Lower
            
            $DIVIDE = $DIVIDE*2
            $Add = 100/$DIVIDE
            
            $Read = GUICtrlRead($Number)
            GUICtrlSetData($Number,Floor($Read-$Add))
            $COUNT += 1
            
    EndSwitch
WEnd
Link to comment
Share on other sites

80? It's actually a piramide of possibilities.

Look I modify your script for numbers between 0 and 1000 and 10 tries is necessary.

I like your script, It's funny. muttley :)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$COUNT = 1
$DIVIDE = 2

MsgBox(0,"Mind Reader","Pick a number between 0 and 1000.")

$Form1 = GUICreate("Mind Reader", 451, 125)
$Lower = GUICtrlCreateButton("My number is lower", 64, 72, 121, 25, 0)
$Correct = GUICtrlCreateButton("That's it", 192, 72, 65, 25, 0)
$Higher = GUICtrlCreateButton("My number is higher", 264, 72, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("Is this your number? :", 72, 32, 104, 17)
$Number = GUICtrlCreateLabel("500", 192, 8, 120, 64)
GUICtrlSetFont(-1, 40, 400, 0, "Arial")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        Case $Correct
            MsgBox(0,"Mind Reader","I knew I could guess it."&@CRLF&"I only tried it "&$COUNT&" times!"&@CRLF&@CRLF&"Ok, again. Pick a number between 0 and 1000.")
            
            GUICtrlSetData($Number,500)
            $COUNT = 1
            $DIVIDE = 2
            
        Case $Higher
            
            $DIVIDE = $DIVIDE*2
            $Add = 1000/$DIVIDE
            
            $Read = GUICtrlRead($Number)
            GUICtrlSetData($Number,Round($Read+$Add))
            $COUNT += 1
            
        Case $Lower
            
            $DIVIDE = $DIVIDE*2
            $Add = 1000/$DIVIDE
            
            $Read = GUICtrlRead($Number)
            GUICtrlSetData($Number,Round($Read-$Add))
            $COUNT += 1
            
    EndSwitch
WEnd

When the words fail... music speaks.

Link to comment
Share on other sites

To check how many retries are required with any number:

$Poss = 1000

$Retries = 0

$i = 0


While 1
    
    If 2^$i < $Poss And 2^($i+1) > $Poss Then 
        $Retries = $i+1
        ExitLoop
    EndIf
    $i += 1
WEnd

MsgBox(0,"bla","Maximal retries: "&$Retries)
Yes. It`s correct.

When the words fail... music speaks.

Link to comment
Share on other sites

Here's my simplified method on how to calculate amount of guesses:

$poss=32
$answer=Ceiling(Log($poss)/Log(2))
MsgBox(0,"Max amount of guesses",$answer)

Math is cool muttley

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...