Rabu, 08 November 2017

Plant Life

The Beaver loves flowers. May be this is the reason why he has invented a simple programming language for visual design based on the idea of plant life.
Each picture starts with a square called a. A visual object can perform three operations: grow(), split() and die().
The following program explains the semantics:
                                                    a.grow(east); a.grow(east) ;

b,c = a.split(); c.grow(north); b.die();
Please note, that only an oblong object may execute the split()-Operation producing two shorter Objects of equal size. A square cannot be split.
Beaver wants to write a program that transforms the left image to the right image. Which could be the first four commands of this program?
Answer:
A. a.grow(east); a.grow(east); b,c = a.split(); b.die();
B. a.grow(north); a.grow(east); a.grow(east); b,c =a.split();
C. a.grow(east); a.grow(east); a.grow (north); a.die();
D. a.grow(east); b,c = a.split(); c.grow(north); c.grow(east);
Solution:
The correct solution is A. This is the complete program: A. a.grow(east); a.grow(east); b,c = a.split(); d,e = c.split(); b.die(); d.die(); e.grow(north);
C does not work because after the fourth command the image is empty. B and D result to rectangles with minimum side lengths of two units. It is impossible to reduce such a shape to a rectangle with a minimum side length of one unit using the split()-Operation. A gardener must grow things carefully!