Boot Sequence
Get the bot to the target square. It starts facing right; bot.move() moves it one square the way it faces.
Each sector is one concept. Write code, run it, rewind it and see what happens line by line. Hardcoded answers get caught by hidden tests.
0/51 sectors
Get the bot to the target square. It starts facing right; bot.move() moves it one square the way it faces.
Reach the target at the end of the bending corridor. bot.turn_left() and bot.turn_right() rotate the bot 90° in place; a turn counts as a step.
Reach the target. At the end of the corridor the way turns up or down, and the direction changes in every test. radar.front_blocked() returns True when a wall is ahead.
Open the gate with the right code and reach the target. radar.read() reads the number on the gate's sensor (an int). Send "LOW" with bot.send(...) if it is below 30, "MID" if below 70, otherwise "HIGH". A wrong code sets off the alarm.
Two security gates stand one after the other, each with its own sensor reading. Instead of writing the same check twice, write a function and call it at both gates. Same rules: below 30 send "LOW", below 70 "MID", otherwise "HIGH".
Reach the target at the end of the long corridor. Your code may be at most 8 lines. The lines inside a for i in range(n): block repeat n times.
Reach the target. It is somewhere else in every test, so you cannot know how many steps to take. bot.at_target() tells you whether you are there; a while loop repeats as long as its condition holds.
Get out of a maze that is generated anew for every test and reach the target. New sensors: radar.left_blocked() and radar.right_blocked() return True when that side is a wall.
Reach the target without hitting a drone. Drones cross the corridor. radar.danger_ahead() tells you whether a step would run into one; bot.wait() waits one turn. Energy is limited: moving costs 1, waiting 0.5.
Reach the target without being caught by a laser. Three lasers blink at different rhythms; a bot entering a cell while its beam is on, or standing in it when the beam turns on, burns. radar.danger_ahead() tells you whether a step is dangerous, bot.wait() waits one turn.
The corridor is a spiral that winds inwards, with the target at its heart. Do not count steps: move while the way ahead is open, turn when it is not. The spiral's direction changes between tests; radar.left_blocked() tells you which way to turn.
The corridor turns down at a corner and two drones cross it: one on the straight, one past the corner. Handle three things together: turn when blocked, wait when there is danger, otherwise move.
Return the largest value in the list. You no longer drive the bot: solve(values) takes a list and returns the answer.
Return the index of key in values. The values are distinct and in no order; in hidden tests the list grows to 800 items.
values is sorted in ascending order and its values are distinct. Return the index of key. Your read budget is at most ⌊log₂ n⌋ + 2: only 14 reads for n = 4096.
Return True if the brackets in the packets are balanced, otherwise False: every opening bracket must close with the right kind in the right order. packets is an iterator: walk it with for ch in packets:; you cannot go back.
Return the shortest route from start to goal. The maze has loops and your energy covers only the shortest path. A route is a string of N/E/S/W letters, e.g. "EESSW"; the bot walks the route you return.
A new rule: the target does not count while a data chip is on the board. The bot takes a chip by stepping on it. The chip lies past the target and its place changes between tests. bot.chips_left() gives the number of chips still to collect.
Halfway down the main corridor is a junction; the chip is in the southern arm, but how many steps in changes between tests. The arm continues north as well, so "walk until the wall" will not bring you back. Keep the steps you take going in in a counter, and take exactly that many coming back.
The corridor's upper wall has alcoves; some hold a chip, and which ones changes between tests. At every cell turn left and look: radar.scan() names what is in front and returns "chip" for a chip. If there is one, step in, take it and step back out.
Chips are scattered across the room, in different places every test. The way to miss none is to sweep the whole room: walk a row, drop down a row at the wall and walk back the other way.
Two drones cross the corridor and one of the chips lies past the target. The same care is needed on the way out and on the way back: put "wait if there is danger, otherwise move" in a function and use it in both loops.
Your energy does not cover sweeping the whole room. radar.map() gives the map row by row: "#" wall, "C" chip, "T" target; read it as grid[y][x]. Find the chips on the map and go straight to them. bot.position() gives the bot's (x, y), and bot.face("E") sets the way it faces ("N", "E", "S", "W").
The same room, less energy. Collecting the chips in map order no longer works: each time, go to the nearest chip. The distance between two cells is abs(x1 - x2) + abs(y1 - y2).
Ten alcoves line the corridor, three of them hold a chip, and which ones changes between tests. Your battery only covers stepping into the full alcoves: enter an empty one and you will not reach the target. You cannot look ahead this time; on the radar.map() map a chip is written as "C". At every cell, read the cell above and the cell below you from the map.
The chips are spread through a maze and your energy is limited. The nearest chip as the crow flies is no longer the nearest: a wall may be in the way. Each time, find the chip that is nearest on foot (BFS), go to it, then walk to the target.
A locked door stands before the target; the key is behind you, somewhere along the corridor. The bot takes a key by stepping on it, and the doors of that colour open. bot.has_key("red") says whether you hold the red key. The key's place changes between tests.
Two ways lead to the target: the left door is red, the right one blue. The key ahead of you opens only one of them, and its colour changes between tests. Take the key, check its colour and choose your way.
No door joins the two rooms, only a pair of teleport pads: a bot that steps on one appears on the other. The exit changes between tests, so on arrival you have to find which side the target is on. radar.scan() sees a pad as "portal"; the target is written as "T" in its row of radar.map().
The key is behind you, the door ahead, and two drones cross the corridor. You have to get past them both on the way to the key and on the way back.
A wall splits the room in two; the only way through is a locked door. The key's place and colour change between tests. On the radar.map() map keys are written in lower case ("r", "b", "g") and closed doors in upper case ("R", "B", "G"). Find the key, take it, go through the door and walk to the target.
Three rooms with walls between them; only teleport pads join them. On the map both ends of a pair carry the same digit ("1", "2"). Until you reach the target, walk to the pad in your room that you have not used yet. The pads move between tests.
The door's key is in the sealed room on the other side of the wall; the only way in is a teleporter, and the way out is the same teleporter. Both ends of the pair, and the key's place and colour, change between tests. Remember the cell you land on: once you hold the key, walk back to that same cell and the pad drops you in the corridor again. On the map a pad is "1" and a key is a lower-case letter ("r", "b", "g").
Three rooms, two locked doors. Each door's key is in the room before that door; colours and places change between tests, and sometimes there is a spare key that fits no door. Open the doors in order from west to east: look at the next door's colour, find the key of that colour, take it, go through. On the map a closed door is an upper-case letter and its key is the same letter in lower case.
Three rooms and two locked doors; the keys, the door colours and sometimes a teleporter are elsewhere in every test. A door can only be passed once its key is held, so "where am I" is not enough: "where am I and which keys do I hold" together make a state. Run BFS over these states.
The chip is at the east end of the corridor and the target is behind you. Take the chip, turn around on the spot and walk to the target. There is no command for turning around: turning the same way twice does it.
A staircase of five steps: every step is the same four commands. Writing them five times breaks the line limit; write the pattern once and let a loop repeat it.
The route is handed to you: "EEENNEEESSSEENNNEE". Each letter is the direction of one step. You have no turn commands; bot.face("N") points you straight at that direction. Walk through the letters of the text in order, facing and stepping once for each.
How far the target is changes with every test, and this time there is no bot.at_target(). All you have is radar.scan(): it says what is in the cell in front of you ("empty", "wall", "target"). Stop the moment you see the target and you are one step short.
The gate's sensor always reads right at the edge: 49 or 50. The rule: send "COLD" if the reading is below 50, and "HOT" if it is 50 or more. This is exactly where < and <= part ways.
The target is right behind you, but the sector is not done until you have the chips in three corners: you have to go round the building. Build a loop inside a loop: the inner one walks to the wall, the outer one turns right at each wall and starts it again.
A corridor curling inwards: sides of 5, 4, 3, 2 and 1 steps, with a right turn after each. You have no sensor. Use the loop variable itself as the step count: range can count backwards too.
There are gates one after another in the corridor. The rule is the same at each: "LOW" if the sensor is below 50, otherwise "HIGH". When there is no gate in front of you, radar.read() returns None, not a number; comparing that with a number is an error. Write one loop that runs to the target.
Three dead ends branch north off the corridor: 2, 4 and 3 cells deep, in that order, each with a chip at the bottom. They are three steps apart. You have no sensor and the line limit is tight: write a function that takes the depth as a parameter and call it for each item of a list.
This time the route comes packed: "3E2N3E3S2E3N2E". Read it in pairs: the number of steps, then the direction (3E = three steps east). Walk the text with an index that advances two at a time; turn the digit into a number with int(...).
These gates have five codes: 0–19 ALFA, 20–39 BRAVO, 40–59 CHARLIE, 60–79 DELTA, 80–99 ECHO. A five-branch if chain does not fit the line limit. Put the codes in a list and compute the right position: every band is 20 wide.
Your radar is broken: you cannot see a wall coming. A bump is no longer fatal, but each one costs 10 health (you have 100). Know the wall by its effect: if bot.position() is the same before and after bot.move(), you did not move. Which way to turn at a corner changes from test to test.
You have 32 units of energy: a step costs 1 and every radar.front_blocked() question costs 2. The way is five corridors, all the same length, turning left, right, left, right at the corners. Ask the radar on every step and you run dry: measure once, keep the result in a variable and reuse it.
You have no map, the maze changes with every test and it has loops in it: following a wall can walk you round the same island for ever. You have bot.position(), bot.face(...), bot.move() and radar.front_blocked(). Keep the cells you have been to in a set; from each cell try the four directions, enter what you have not seen, and step back when it leads nowhere.
An empty hall, a few chips and energy for exactly 18 steps. The rule "always go to the nearest chip" runs dry here: the near chip pulls you away from the target and back. There are only a few chips: try every order, work out the total distance of each and walk the shortest.
There is no door between the two rooms: the only way across is by teleport pads. Two pads with the same digit on the map are linked; step on one and you appear on the other. Your energy just covers the shortest way, and the nearest pad is not always the right one. Write a BFS that counts the pads as edges too: stepping onto a pad puts you on its partner.