Skip to content
Game 6 Unit 3 of 6 1 hr learning time

Higher or Lower

A wrong guess should teach something. Add two comparisons — is the guess below the code, or above it? — and a miss becomes a direction. This is the clue that turns blind guessing into deduction.

50% of Safe Cracker

A miss that tells you nothing is no help. A miss that tells you which way to go is everything. So when the guess is wrong, don't just say so — say whether the code is higher or lower. That one clue is what turns a guessing game into a thinking game.

10 PRINT CHR$(147)
20 S=INT(RND(1)*100)+1
30 INPUT "YOUR GUESS";G
40 IF G=S THEN PRINT "CRACKED IT!":END
50 IF G<S THEN PRINT "THE CODE IS HIGHER"
60 IF G>S THEN PRINT "THE CODE IS LOWER"
A C64 screen reading YOUR GUESS? 50, THE CODE IS LOWER.
A miss that teaches: 50 was too high, so the code is lower. The player now knows to aim below 50 — the search has a direction it didn't have before.

Two new lines do it. Line 50, IF G < S THEN PRINT "THE CODE IS HIGHER", fires when the guess is below the secret — the code is higher than what they tried. Line 60, IF G > S THEN PRINT "THE CODE IS LOWER", fires when the guess is above it. Only one can be true on any wrong guess, so the player gets exactly one clue.

The wording matters. The hint is phrased from the safe's point of view — "the code is HIGHER" — so the player knows which way to move their next guess, not just that they were wrong. Now each guess does double duty: it might be the answer, and if it isn't, it rules out half the remaining numbers. Guess 50 and hear "lower", and you've eliminated everything from 50 to 100 in one go. That halving is deduction, and it's the heart of the game.

Try this

  • Halve it yourself. Always guess the middle of what's left — 50, then 25, then between — and count how few guesses it takes. That's binary search, and you're doing it by instinct.
  • Two clues, never both. Notice that a single guess never prints both hints. The < and > tests can't both be true, so the safe gives one clear direction.

What's next

The clue points the way, but the program still stops after one guess. In Unit 4 a loop lets the player keep guessing — narrowing in, hint after hint, until the safe opens.