Practice
Secret Cell Hunt
2024/May/June·Variant 2·Q11·[15 marks]
HARD2D Arrays
A 5×5 grid stores one hidden flag "F". The player starts at cell [1, 1] and has at most 10 successful moves.
Read the flag's row and column (not [1, 1]). Then read moves as L, R, U, or D (uppercase or lowercase). A move that would leave the grid, or any other character, is invalid: output Invalid move and do not count it.
After each successful move, check whether the player landed on the flag. Output You Win if they find it in 10 moves or fewer, otherwise You Lose.
Input: Flag row, flag column, then move letters.
Output: Invalid move for each rejected attempt, then You Win or You Lose.
Example:
Input: 1
3
R
R
Output: You Win
Sample Test Cases
Test 1: Two steps right onto the flag
Inputs: 1, 3, R, R
Expected: You Win
Test 2: Ten valid moves that miss the flag
Inputs: 5, 5, R, L, R, L, R, L, R, L, R, L
Expected: You Lose