The Polish mathematician Wacław Sierpiński once designed a famous fractal known as the Sierpiński Carpet, a beautiful and infinitely complex pattern created by recursively removing parts of a square. But what if we could modify the removal pattern?
You have discovered a Generalized Sierpiński Carpet, where the recursion follows a custom $$$3 \times 3$$$ pattern $$$P$$$ consisting of the characters '*' and '.'. Your task is to generate and print this fractal for a given number of recursion steps.
Let's say that $$$S_n$$$ is the Generalized Sierpiński Carpet with $$$n$$$ recursive steps, we define $$$S_n$$$ as follows:
Given $$$n$$$ and $$$P$$$, print $$$S_n$$$.
The first line contains a single integer $$$n$$$ ($$$0 \leq n \leq 6$$$) – the number of recursive steps.
Each of the $$$3$$$ lines contains $$$3$$$ characters, where each character is either '*' or '.' – the description of $$$P$$$.
Print $$$S_n$$$.
2****.****
********* *.**.**.* ********* ***...*** *.*...*.* ***...*** ********* *.**.**.* *********
2*.*.*.*.*
*.*...*.* .*.....*. *.*...*.* ...*.*... ....*.... ...*.*... *.*...*.* .*.....*. *.*...*.*
1*...*.***
*.. .*. ***