You may recall that in stage 1 of the CCC you were asked to calculate a region of a fractal obtained by starting with a square, dividing it into 9 sub-squares, then clearing the middle, like so:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *This operation was then repeated for each of the 8 remaining sub-squares, and so on.
If we choose a different operation we get a different fractal; for example, we may clear the upper-left and lower-right corners instead of the middle. Or we may divide the square into a different number of sub-squares.
For this problem we will specify the fractal operation as an n by n grid of characters, where each character performs a particular substitution on the corresponding sub-square. The character . (period) indicates that the corresponding sub-square becomes completely empty. The character ! (exclamation mark) indicates that the corresponding sub-square becomes full and is not subject to further fractal operations. The character ? (question mark) indicates that the corresponding sub-square remains full and is subject to further fractal operations.
The fractal above would be represented by the 3 by 3 grid:
??? ?.? ???Four iterations of the fractal denoted by the 2 by 2 grid
.! ?.would be:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Your mission, should you choose to accept it (like you have any choice!) is to print out a region of an arbitrary fractal specified by an n by n grid. Note that these fractals will get way too big to fit completely into memory, so some cleverness will be required to compute only the part to be printed. (Part marks can still be earned for programs that work only on small examples.)
2 .! ?. 3 2 8 1 7 -1
* * * * * * * * * * * * * * * * *