print " Think of a Number between 1 and 127"
print "press RETURN when you have picked a number"
print "and I will present you with 7 screens of numbers"
print "on each screen of numbers, see if your number is there"
print "and answer y or n to the question"
print
dim as integer i, j, m, n, k, l, p, yn = 0
dim as string a
m = 7
n = (2 ^ m) - 1
DIM as integer c(m, (2 ^ (m - 1)))
k = 1
l = 1
input "Press Return to start ";a
WHILE k < n
p = 1
FOR i = k TO n STEP k * 2
FOR j = i TO i + k - 1
c(l, p) = j
p = p + 1
NEXT
NEXT
l = l + 1
k = k * 2
WEND
FOR i = 1 TO m
FOR j = 1 TO (2 ^ (m - 1)) STEP 4
print using "####";c(i, j);
PRINT using "####";c(i, j + 1);
PRINT using "####";c(i, j + 2);
PRINT using "####";c(i, j + 3)
NEXT j
INPUT "is your number there? ",a
if a = "y" then yn+=c(i,1)
cls
NEXT i
print "your number is ";yn
sleep
Print " Think of a Number between 1 and 127"
Print "press RETURN when you have picked a number"
Print "and I will present you with 7 screens of numbers"
Print "on each screen of numbers, see if your number is there"
Print "and answer y or n to the question"
Print
Dim As Integer i, j, m, n, k, l, p, yn = 0
Dim As String a
m = 7
n = (2 ^ m) - 1
Dim As Integer c(m, (2 ^ (m - 1)))
k = 1
l = 1
Input "Press Return to start ";a
While k < n
p = 1
For i = k To n Step k * 2
For j = i To i + k - 1
c(l, p) = j
p = p + 1
Next
Next
l = l + 1
k = k * 2
Wend
For i = 1 To m
For j = 1 To (2 ^ (m - 1)) Step 4
Print Using "####";c(i, j);
Print Using "####";c(i, j + 1);
Print Using "####";c(i, j + 2);
Print Using "####";c(i, j + 3)
Next j
'------------------------------------
If Bit(79,(i-1)) Then '<- NUM3ER
a="y"
Else
a="n"
EndIf
Print "is your number there? ",a
Sleep 1000
'------------------------------------
If a = "y" Then yn+=c(i,1)
Cls
Next i
Print "your number is ";yn
Sleep
Print "A different version of the guessing puzzle:"
Print
Print "Think of a Number between 0 and 127"
Print "press RETURN when you have picked a number"
Print "and I will present you with 7 screens of numbers"
Print "on each screen of numbers, see if your number is there"
Print "and answer y or n to the question"
Print
Dim As String s
Input "Press Return to start ";s
Dim As Integer page, printcount
Dim As UByte count
Dim As UByte mask = 127
Dim As UByte thisbit = 1
For page = 1 To 7
Cls
printcount = 0
For count = 1 To 127
If count And thisbit Then
Print count,
printcount += 1
If printcount = 4 Then
Print
printcount = 0
EndIf
EndIf
Next
Print
Input "Is your number here (y/n)";s
If LCase(Left(Trim(s),1)) = "n" Then mask -= thisbit
thisbit *= 2
Next
Print "You were thinking of the number: " & mask
Sleep
Ok, here's how it works, admitedly the the way the array is calculated is brute.
1: (print first screen of numbers) Print all number between 1 and 127 whose bit 0 is set.
2: (print second screen of numbers) Print all number between 1 and 127 whose bit 1 is set.
and so on for the rest.
notice that the top-lef numbers are powers of 2, to get the number that was picked add the powers of 2 where the number is present.
because any number can be represented as the sum of powers of 2.
print " Think of a Number between 1 and 127"
print "press RETURN when you have picked a number"
print "and I will present you with 7 screens of numbers"
print "on each screen of numbers, see if your number is there"
print "and answer y or n to the question"
print
dim as integer i, j, k, yn = 0
dim as string a
input "Press Return to start ";a
for k=0 to 7-1
i=1
do
j=0
do
if bit(i,k) then
print using "####";i;
j+=1
end if
i+=1
loop until j=4
print
loop until i>127
input "is your number there? ",a
if a = "y" then yn+=2^k
next
print "your number is ";yn
sleep
<edit> @marcov
that's it.
Last edited by srvaldez on Sep 17, 2010 17:10, edited 1 time in total.
Print "A variation on the guessing puzzle:"
Print
Print "Think of a Number between 0 and 127"
Print "press RETURN when you have picked a number"
Print "and I will present you with 7 screens of numbers"
Print "on each screen of numbers, see if your number is there"
Print "and answer y or n to the question"
Print
Dim As String s
Input "Press Return to start ";s
Dim As Integer page, printcount
Dim As UByte count
Dim As UByte mask = 127
Dim As UByte thisbit = 1
Dim As Byte notmap(1 To 127)
For page = 1 To 7
Cls
printcount = 0
For count = 1 To 127
If count And thisbit And (notmap(count) = 0) Then
Print count,
printcount += 1
If printcount = 4 Then
Print
printcount = 0
EndIf
EndIf
Next
Print
Input "Is your number here (y/n)";s
If LCase(Left(Trim(s),1)) = "n" Then
mask -= thisbit
For count = 1 To 127
If count And thisbit Then notmap(count) = 1
Next
EndIf
thisbit *= 2
Next
Print "You were thinking of the number: " & mask
Sleep