Night 25: Find the treasure
Vous avez déjà terminé cette soirée, en Python ou en pseudocode. Elle compte pour les deux. Entraînez-vous à nouveau si vous le souhaitez.
Tonight: find the treasure
- Treasure is buried somewhere on the map! Your pet digs to find it.
- Nothing new to learn: you use
WHILE,IF,ANDand a flag together.
Words for tonight
| Word | Meaning |
|---|---|
| treasure | gold and other things of great value |
| dig | make a hole in the ground |
| distance | how far it is from one place to another |
Both must be right
- The treasure is at
X = 3,Y = 1. A dig is right only when both match.
DECLARE X, Y : INTEGER
X ← 3
Y ← 4
IF X = 3 AND Y = 1 THEN
OUTPUT "Treasure!"
ELSE
OUTPUT "Nothing here"
ENDIF

A flag stops the loop
- A flag is a BOOLEAN. It remembers if something happened.
DECLARE Found : BOOLEAN
DECLARE Digs : INTEGER
Found ← FALSE
Digs ← 0
WHILE NOT Found
Digs ← Digs + 1
IF Digs = 3 THEN
Found ← TRUE
ENDIF
ENDWHILE
OUTPUT "Found after ", Digs, " digs"
NOT Foundis TRUE whileFoundis FALSE.
The order of the hints
- Check
Xfirst, thenY. When you testY, you already knowXis right.
| Test | Hint |
|---|---|
X < 3 |
Go right |
X > 3 |
Go left |
Y < 1 |
Go down |
| otherwise | Go up |
- Now help your pet find the treasure!
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
Treasure is buried at X = 3, Y = 1. Read where the pet digs: X, then Y. Output Treasure! ou Nothing here.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Help the pet! After a wrong dig, output one hint. If X is wrong, output Go right (X is too small) or Go left. If only Y is wrong, output Go down (Y too small) or Go up.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Let the pet dig again and again. Read X et Y for each dig. Output Nothing here after each miss. When it finds the treasure, output Treasure! Found in , the number of digs, then digs.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 4/5 · 280 pièces + un petit bonus lors de la première réussite aujourd'hui
A better hint: how many steps away is the treasure? Read X et Y. If it is the treasure, output Treasure!. Otherwise output the steps, like 3 steps away. Steps are the X-distance plus the Y-distance.
Cliquez sur Exécuter pour voir le résultat ici.