Author Topic: Hi Lo without Secret Number?  (Read 3594 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Hi Lo without Secret Number?
« on: October 11, 2020, 04:35:43 pm »
You know the Hi Lo Number Guessing Game where you keep guessing until you guess a secret number between 1 and 100.

Could you tell if the game had no secret number? Can you create such a game?

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
Re: Hi Lo without Secret Number?
« Reply #1 on: October 11, 2020, 04:48:49 pm »
who is doing the guessing, the user or the PC?

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Hi Lo without Secret Number?
« Reply #2 on: October 11, 2020, 05:07:40 pm »
I want to see something in this question, but I can't yet - are you saying that the computer says "go higher" or "go lower" with a given guess, but you never get it right?

Just choose an irrational number for an answer, the user can never type it all out.
You're not done when it works, you're done when it's right.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
Re: Hi Lo without Secret Number?
« Reply #3 on: October 11, 2020, 05:07:59 pm »
ok, bplus
here's a small progie that will guess a number that you pick between 1 and 127
Code: [Select]
_TITLE "number guess" 
PRINT " Think of an Integer 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 i%, j%, m%, n%, k%, l%, p%, yn%
yn% = 0
DIM a$
m% = 7
n% = (2 ^ m%) - 1
DIM 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% = yn% + c%(i%, 1)
    CLS
NEXT i%
PRINT "your number is "; yn%
SLEEP

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
Re: Hi Lo without Secret Number?
« Reply #4 on: October 11, 2020, 05:19:58 pm »
version 2, pick an integer between 1 and 31
Code: [Select]
_TITLE "number guess"
DIM a$
m% = 5
n% = (2 ^ m%) - 1
PRINT " Think of an Integer Number between 1 and "; n%
PRINT "press RETURN when you have picked a number"
PRINT "and I will present you with "; m%; " 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 i%, j%, k%, l%, p%, yn%
yn% = 0
DIM 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% = yn% + c%(i%, 1)
    CLS
NEXT i%
PRINT "your number is "; yn%
SLEEP

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #5 on: October 11, 2020, 05:32:29 pm »
Here is a reminder how the usual game of Hi Lo goes:
Code: QB64: [Select]
  1. 'now 4 lines
  2. 1 num = ABS(INT(99 * SIN(TIMER * RND)))
  3. 2 INPUT "Guess my number between 1 and 100 (inclusive) ", guess
  4. IF guess < num THEN PRINT "Higher" ELSE IF guess > num THEN PRINT "Lower" ELSE IF guess = num THEN PRINT "Correct. You Win"
  5. IF guess = num THEN GOTO 1 ELSE GOTO 2
  6.  

Line 1 would normally be:

Code: QB64: [Select]
  1. num = int(rnd *100) + 1

The program generally starts by picking a random number between 1 and 100 and having the player/user guess. If the guess is not the number, then the program says if the guess was too High or too Low, thus the name of the Game Hi Lo.

One can write a program to appear to be using a Random number "secret" but in fact never has a secret number. It goes by other things to say if correct or too high or too low.

The numbers guessed will have the same random distribution between 1 and 100 as a normal program with a secret number. ie with 10000 games played, each number guessed between 1 and 100 will have been played around 100 times.
« Last Edit: October 11, 2020, 05:33:48 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #6 on: October 11, 2020, 05:35:40 pm »
Hey jack,

I know and seen your version too, but not what I had in mind for here.

I did that trick or variation with 27 cards. Cool!
« Last Edit: October 11, 2020, 05:36:50 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #7 on: October 11, 2020, 05:39:19 pm »
Yes, @johnno56 @jack  (I saw Spock and just assumed Johnno Ha, ha!) you are guessing a number from 1 and 100 and the computer program has not set a secret number but "fakes it" so to speak when it says you are too high or low or have guessed the number.
« Last Edit: October 11, 2020, 05:51:51 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Hi Lo without Secret Number?
« Reply #8 on: October 11, 2020, 05:42:52 pm »
I am so confused. Isn't f(RND) just as unpredictable as RND in the way you've used it? What's *not* secret about RND? You never know what it's result is until you bite into it.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #9 on: October 11, 2020, 05:43:14 pm »
@STxAxTIC  the program does say go higher or too high... but it also will say if you guessed.

BTW there is a 1 in 100 change you will guess right, right off the bat!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #10 on: October 11, 2020, 05:46:34 pm »
I am so confused. Isn't f(RND) just as unpredictable as RND in the way you've used it? What's *not* secret about RND? You never know what it's result is until you bite into it.

Yes well RND is used quite a bit but no random number secret is set in stone when you start guessing.

And when you play the game you would not be able to tell the difference.
« Last Edit: October 11, 2020, 05:48:09 pm by bplus »

Offline Gets

  • Newbie
  • Posts: 28
Re: Hi Lo without Secret Number?
« Reply #11 on: October 11, 2020, 07:10:14 pm »
You know the Hi Lo Number Guessing Game where you keep guessing until you guess a secret number between 1 and 100.

Could you tell if the game had no secret number? Can you create such a game?

A correct answer would be generated by high/low responses regardless of whether it was chosen before the game started, and reaching that value is exactly where players would be able to tell no such number existed.

So the goal of such a program would be to keep track of previous guesses and responses and give false information for as long as possible without getting caught. Basically looking for an opportunity to tell the player that 31 is low, after it already said 30 is high, without the player noticing.

It's doable, but probably needs to be based on a more complex game in order to really pull it off.

Something like a Rubix Cube that shuffles squares around when  you aren't looking.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #12 on: October 11, 2020, 07:40:33 pm »
Quote
Basically looking for an opportunity to tell the player that 31 is low, after it already said 30 is high, without the player noticing.

Nope, no way, that's lying and cheating. It does track the low and high it's told the player and stays consistent with what it says.

And like in jack's variation you must arrive at the answer in maybe 7 guesses or less specially if user is using a Binary search method.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Hi Lo without Secret Number?
« Reply #13 on: October 11, 2020, 08:00:43 pm »
Code: QB64: [Select]
  1. 1 SCREEN _NEWIMAGE(1280, 720, 32)
  2. 2
  3. 3 FOR j = 0 TO 1
  4.   4 CLS
  5.   5 PRINT "Bite MY Lucky Seven"
  6.   6 PRINT "Most games want you to guess from 1 to 100, but I'm smarter than them."
  7.   7 PRINT "Choose any whole number from 0 to 127, and give me 7 guesses."
  8.   8 PRINT "I bet after that time, I can tell you what the number is."
  9.   9 PRINT CHR$(13); "Choose your number and press any key to begin"
  10.   10 junk$ = INPUT$(1)
  11.   11 guess = 64
  12.   12 CLS
  13.   13 FOR i = 5 TO 0 STEP -1
  14.       14 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i + 1)
  15.       15 PRINT "For Guess #"; (6 - i); ", my guess is"; guess
  16.       16 PRINT CHR$(13); "Am I:  (0) Correct   (1) High   (2) Low"; CHR$(13)
  17.       17 PRINT "PRESS 0, 1, or 2 please for your answer =>";
  18.       18 a = VAL(INPUT$(1))
  19.       19 PRINT a; CHR$(13); CHR$(13)
  20.       20 i = i - ((a - 1) AND 2) / 2 * i 'answer 0, and we win
  21.   21 NEXT
  22.   22 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i +1)
  23.   23 PRINT "Your number is "; guess
  24.   24 PRINT
  25.   25 PRINT "Would you like to:     (1) Try again"
  26.   26 PRINT "                       (2) Run away crying, unable to stop my awesome power"
  27.   27 a = VAL(INPUT$(1))
  28.   28 j = 1 - (1 AND a)
  29. 29 NEXT
  30. 30 END

There’s my overly complex version of this problem, without any use of IFs, or conditional statements.  It was my entry in an old 30-line code challenge back over at .net, ages ago.  ;)
« Last Edit: October 11, 2020, 08:01:55 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
Re: Hi Lo without Secret Number?
« Reply #14 on: October 11, 2020, 08:22:37 pm »
you can also find it at the Rosetta Code http://rosettacode.org/wiki/Guess_the_number/With_feedback_(player)
I translated the bbc basic code http://rosettacode.org/wiki/Guess_the_number/With_feedback_(player)#BBC_BASIC
Code: QB64: [Select]
  1. min% = 1
  2. max% = 100
  3. PRINT "Think of a number between "; min%; " and "; max%
  4. PRINT "I will try to guess your number."
  5.     guess% = (min% + max%) \ 2
  6.     PRINT "My guess is "; guess%
  7.     INPUT "Is it higher than, lower than or equal to your number ", answer$
  8.     SELECT CASE LEFT$(answer$, 1)
  9.         CASE "L", "l": min% = guess% + 1
  10.         CASE "H", "h": max% = guess% - 1
  11.         CASE "E", "e": EXIT DO
  12.         CASE ELSE: PRINT "Sorry, I didn't understand your answer."
  13.     END SELECT
  14. LOOP UNTIL FALSE
  15. PRINT "Goodbye."
  16.