Jump to content
Sign in to follow this  
Kip

I can guess your number in less than 8 times.

Recommended Posts

Kip

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

Share this post


Link to post
Share on other sites
tlokz

Lmao, this is pretty sweet i played with it for like 10 minutes straight trying to trick it but i couldnt :)

I like it muttley

Share this post


Link to post
Share on other sites
Andreik

Is not a Mind Reader, is pure math but I like your script, is very funny. muttley


When the words fail... music speaks

Share this post


Link to post
Share on other sites
Uriziel01

Hehe muttley Tricky and nice scripted :)


Share this post


Link to post
Share on other sites
Kip

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

Share this post


Link to post
Share on other sites
Andreik

If I choose my number between 0 and 1000, how retries? muttley


When the words fail... music speaks

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
Andreik

How this program can guess your number (If your not so good at math)

Posted Image

muttley I`m not so good at math???

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Andreik

I was talking in general

If I see the script, I know algorithm from guess my number. Anyway a good script.

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Kip

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)

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
BrettF
monoceres

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!

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.