Lesson 43: Think in squares
Keep what matters
- A delivery robot does not need to think in millimetres. It needs to know which square to go to.
- Abstraction means keeping only the details that matter and leaving out the rest.
- Here the floor becomes a grid of squares.
go_to(col, row)hides the millimetres and the angles.
Words for this lesson
| Word | Meaning |
|---|---|
| abstraction | keeping only the important details |
| grid | rows and columns of squares |
| global variable | a variable that every function can use |
Squares and millimetres
| Square | x (mm) | y (mm) |
|---|---|---|
| (0, 0) | −800 | −800 |
| (4, 3) | 0 | −200 |
| (2, 6) | −400 | 400 |
- One square is 200 mm, so x = −800 + 200 × col.
In the exam
- 0478/21/O/N/23 Q5(a): describe what is meant by abstraction. Mark scheme: simplifying the problem; removing unnecessary details (keeping only the elements needed); filtering out characteristics that are not relevant.
- A map is a good example: it shows roads and places, and leaves out the colour of every house.
ความยาก 4/5 · 280 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Forget millimetres: think of the floor as squares of 200 mm. The robot starts in square (0, 0) at the bottom left. go_to(col, row) should drive to any square. The column part is written: it turns to face right (90) or left (270) and drives. Write the row part the same way: up is heading 0, down is heading 180. Then go_to(4, 3) และ go_to(2, 6) reach the checkpoint and the goal.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A delivery route is a list of squares: [[3, 0], [3, 4], [6, 4], [6, 7], [1, 7]]. Visit them in order with a loop and go_to. Each square except the last is a checkpoint; the last is the goal.
คลิก Run เพื่อดูผลลัพธ์ที่นี่