ULM02 - The Sierpinski Fractal

no tags 

Consider a regular triangular area, divide it into four equal triangles of half height and remove the one in the middle. Apply the same operation recursively to each of the three remaining triangles. If we repeated this procedure infinite times, we'd obtain something with an area of zero. The fractal that evolves this way is called the Sierpinski Triangle. Although its topological dimension is 2, its Hausdorff-Besicovitch dimension islog(3)/log(2)~1.58, a fractional value (that's why it is called a fractal). By the way, the Hausdorff-Besicovitch dimension of the Norwegian coast is approximately 1.52, its topological dimension being 1.

For this problem, you are to outline the Sierpinski Triangle up to a certain recursion depth, using just ASCII characters. Since the drawing resolution is thus fixed, you'll need to grow the picture appropriately. Draw the smallest triangle (that is not divided any further) with two slashes, to backslashes and two underscores like this:

     /\
    /__\

To see how to draw larger triangles, take a look at the sample output.

Input

The input contains several testcases. Each is specified by an integer n. Input is terminated by n = 0. Otherwise 1 ≤ n ≤ 10 indicates the recursion depth.

Output

For each test case draw an outline of the Sierpinski Triangle with a side's total length of 2n characters. Align your output to the left, that is, print the bottom leftmost slash into the first column. The output must not contain any trailing blanks. Print an empty line after each test case.

Sample

Input:
3
2
1
0

Output:
       /\
      /__\
     /\  /\
    /__\/__\
   /\      /\
  /__\    /__\
 /\  /\  /\  /\
/__\/__\/__\/__\

   /\
  /__\
 /\  /\
/__\/__\

 /\
/__\

hide comments
Shubham Jadhav: 2020-07-14 20:11:16

read the input format properly :P cost me two WA

nadstratosfer: 2017-10-31 19:04:42

Try URJC2_F if you enjoyed this.

Szymon: 2015-05-13 15:47:46

don't forkget not to put trailing blanks
cost me 4x WA

Flago: 2014-02-26 11:08:27

Ahahah, 5 WAs because I can't read input conditions and I tho the Sample was "3" cases : "{2,1,0}" :X
Easy problem for php :D

Alexandre Henrique Afonso Campos: 2014-01-05 20:45:19

Any tip for getting rid of TLE? Even using C++ and freopen I can't make it on time.

Last edit: 2014-01-08 14:24:23

Added by:abdelkarim
Date:2013-08-28
Time limit:1s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:University of Ulm Local Contest 2002