Skip to content / Đến nội dung
ThichHocToan.com

BEBRAS 2017 Grade 9-10 Round 2 Ext Question 6

BEBRAS · BEBRAS 2017 Grade 9-10 Round 2 Ext

Question 6

Recursive drawing can create complex patterns from a few instructions, sometimes called algorithmic art. These are examples of a Koch curve and recursive circles.

Question illustration

Question illustration

Recursion means that a function calls itself, like repeated reflections between facing mirrors. The source gives this DrawSquare(x,y,s) algorithm:
1. Draw a square of side s centered at (x,y).
2. If the side length is smaller than 2 pixels:
DrawSquare(x+s/2,y,s/2), a smaller square to the right;
DrawSquare(x−s/2,y,s/2), a smaller square to the left.
Which pattern can be produced?

Question illustration

Editorial convention for the conditional answer: preserve the printed “smaller than” rule above, but for a terminating drawing interpret recursion as continuing while s≥2 and stopping after drawing when s<2. The intended correction is not confirmed by the source.
  1. Pattern A
  2. Pattern B
  3. Pattern C
  4. Pattern D