Recursion and computational thinking · A level · OCR H446 2.1.1, AQA 7517 4.4.1.3 · about 20 min
Representational abstraction, generalisation, problem reduction, and a grid model of the mat that differs from reality.
[1 mark]What is abstraction?
[1 mark]A metro map shows stations in the right order on each line but ignores real distances and bends. What kind of abstraction is it?
[1 mark]"A time-of-flight sensor is a kind of distance sensor, which is a kind of sensor." Which kind of abstraction is this?
[1 mark]A room is modelled as a grid of 20 cm cells, blocked if the centre of the cell is inside an obstacle. What is a danger of this abstraction?
[1 mark]Euler turned the Königsberg bridges puzzle into a question about points and lines. What is this an example of?
[1 mark]Why is abstraction needed when solving problems with computers?
Tick every answer that is true.
The mat is 100 cm by 100 cm, with (0, 0) in the bottom left corner. The four obstacles in the figure are these rectangles, each (x, y, width, height) in cm, where (x, y) is the rectangle's bottom left corner:
(25, 64, 40, 10), (72, 5, 8, 50), (5, 22, 30, 16) and (84, 40, 12, 60)
Build the 5 by 5 grid model with 20 cm cells.
- Write a function blocked(cx, cy) that returns True if the point (cx, cy) is inside any rectangle (a point exactly on an edge counts as inside) and False otherwise.
- A cell is blocked if its centre is blocked. Row 0 is the top row of the mat and column 0 the left, so the cell in row 0, column 0 has its centre at (10, 90).
- Print the five rows, row 0 first, each as a string of five characters: # for a blocked cell and . for a free one.
- Then print blocked: <n>, the number of blocked cells.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
obstacles = [(25, 64, 40, 10), (72, 5, 8, 50), (5, 22, 30, 16), (84, 40, 12, 60)]
def blocked(cx, cy):
return FalsePlan your program here, then type it in and press Run.