# I can guess your number in less than 8 times.

## 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

\$COUNT += 1

Case \$Lower

\$DIVIDE = \$DIVIDE*2

\$COUNT += 1

EndSwitch
WEnd```

##### Share on other sites

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 on other sites

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

When the words fail... music speaks

##### Share on other sites

Hehe muttley Tricky and nice scripted

##### Share on other sites

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

\$COUNT += 1

Case \$Lower

\$DIVIDE = \$DIVIDE*2

\$COUNT += 1

EndSwitch
WEnd```

##### Share on other sites

whoops double post.

##### Share on other sites

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

##### Share on other sites

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

When the words fail... music speaks

##### Share on other sites

80? It's actually a piramide of possibilities.

##### 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

\$COUNT += 1

Case \$Lower

\$DIVIDE = \$DIVIDE*2

\$COUNT += 1

EndSwitch
WEnd```

When the words fail... music speaks

##### Share on other sites

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

##### Share on other sites

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

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

When the words fail... music speaks

##### Share on other sites

I was talking in general

##### Share on other sites

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 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)```

##### 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

##### Share on other sites

Cool! To guess a number between 0 and one million, it only has to take 20 retries.

##### Share on other sites

Once you get the number, and if you press the button, it still counts it as a try... muttley

Otherwise i like!

##### Share on other sites

Yes, because when you start over, it starts with a "guess"

##### Share on other sites

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

```\$poss=32

Math is cool muttley

Edited by monoceres

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

## Create an account

Register a new account

×

• Wiki

• Back

• Git