Fractals
Time limit1sMemory limit128 MB
Draw a level-`level` block fractal of given width from (0,1) to (width,1) and list, in order, every integer y where the vertical line x meets a segment.
- Level
Medium6 of 10
- Topics
- Recursion, Implementation, Simulation, Geometry
- Solved
- No attempts yet
Problem
A fractal is a geometric shape whose overall pattern repeats itself, identical to the whole, within each of its parts. Consider the simple "block fractal" described below. At every stage of the fractal's growth, each line segment in the fractal is divided into three equal parts. The first and last parts stay straight, but the middle part is replaced by a square "bump" whose height equals the width of that middle part. (You must consider the four orientations a segment can take. Depending on the direction of the segment currently being drawn, the bump may protrude up, down, left, or right.)
Draw this fractal on a Cartesian plane with at the bottom-left corner. The fractal's bottom-left endpoint is at and its bottom-right endpoint is at . For example, in a level fractal of width , the highest part is the segment from to .
Write a program that tracks the integer coordinate points crossed by the segments of a "block fractal" whose bottom-left corner is at . Given the vertical line , report every integer where that line meets a segment of the fractal.
You may draw the fractal for debugging or interest, but some fractals may be too large to fit on one screen.
Input
One line with three integers: the level , the width , and the x-coordinate , separated by spaces. The width is a power of and is large enough that every corner of the fractal lands on an integer lattice point (that is, is a multiple of ). The width never exceeds . The value is an integer with .
Output
Print, on one line, every integer for which the point lies on a segment of the fractal, sorted in ascending order and separated by single spaces.