# Beta's Snowflake

## Challenge

Winter is fast approaching with many places receiving the first layers of snow for the 15/16 season, so why don't we break out the snow machines and code ourselves some snow?

Given a integer n via STDIN, output an ASCII representation Beta's snowflake (as described below) at level n.

## Beta's Snowflake

The snowflake starts off at level 0 with a single x:

x


Then, on each corner you add one of these shapes:

x
xx


You add the above shape to a top right corner. For a bottom right corner, rotate it 90° clockwise, for bottom left, 180° clockwise and for top left, 270° clockwise.

If you do that, you get the following shape:

 x x
xx xx
x
xx xx
x x


Take note of the orientation of the shapes. Carrying on we add more of the shapes to each corner, using the orientation rules described above, to the diagram to get level 2:

  x x x
xxxxxxx
xx x x xx
xxx xxx
xx  x  xx
xxx xxx
xx x x xx
xxxxxxx
x x x


Note that the shapes are only added to xs with two or more exposed sides (which is referred to as a corner above).

The L-shapes may and will overlap for values of n greater than 1. For example:

If level 0 is:

x x


Then there must be overlaps in level 1 (indicated with an o, do not include the o in your output):

 x o x
xxxoxxx
x x
xxxoxxx
x o x


## Bonus

There will be a 50 rep bonus for the shortest program which, when n is negative, outputs the snowflake (at level n*-1) as an image or graphically to the screen.

You may have a separate programs for the bounty and the main task.

## Winning

The shortest program in bytes wins.

• A gamma snowflake is a 3d version of this. – Conor O'Brien Oct 26 '15 at 18:06
• @CᴏɴᴏʀO'Bʀɪᴇɴ Well that's an idea for a follow up challenge ;) – Beta Decay Oct 26 '15 at 18:08
• Can you clarify the 2 or more exposed sides rule? Assuming center is 0,0 then 1,1,1,-1,-1,-1,-1,1 all have 2 exposed sides (the sides facing towards the other 4 points). Shouldn't it be 3+ open sides to avoid infilling? Or alternately it only expands if it has 0 or 1 neighbors (cardinal). – Jonathan Leech-Pepin Nov 5 '15 at 14:55
• As per above, it would also lead to additional growth in cases like n=2 on the corners of the 'square' around the center (it is not a peak, but it is exposed on the W,NW,N sides (for top left). – Jonathan Leech-Pepin Nov 5 '15 at 14:58

# CJam, 8883 82 bytes

1]]{{0f+zW%}8*{YYb_m*{~W\$m>fm>}%z:z8Ybff=__1m>\1fm>]:zWf%(\:..|}4*..|}q~*" x"ff=N*


Test it here.

I think I can save a lot in how I detect where the corners are. But at least I finally know what the next iterations look like:

N = 3:

   x x x x
xxxxxxxxx
xx x x x xx
xx xxxxxxx xx
xxx x x xxx
xx xxx xxx xx
xxx  x  xxx
xx xxx xxx xx
xxx x x xxx
xx xxxxxxx xx
xx x x x xx
xxxxxxxxx
x x x x


N = 4:

    x x x x x
xxxxxxxxxxx
xx x x x x xx
xx xxxxxxxxx xx
xx xx x x x xx xx
xxx xxxxxxx xxx
xx xxx x x xxx xx
xxx xxx xxx xxx
xx xxx  x  xxx xx
xxx xxx xxx xxx
xx xxx x x xxx xx
xxx xxxxxxx xxx
xx xx x x x xx xx
xx xxxxxxxxx xx
xx x x x x xx
xxxxxxxxxxx
x x x x x


Looking at these, they seem to be a lot more regular than I expected, and some sort of analytic solution which generates them directly might be much shorter.

# Python 2, 269 bytes

Doesn't place the shapes at each corner, but determines whether a character is in the snowflake based on the coordinates.

First one corner is generated, and then mirrored around to the full snowflake.

i=input()
d=2*i+1
s=[x[:]for x in[[0]*d]*d]
s[0][0]=1
if i:s[1][1]=1
for j in range(2,d):
for v in range(j+1):s[j][v]=s[v][j]=(j+v)%3!=1and j+v<d+i if v>j/2 else j%2==1or j%4+v%2in[0,3]
for l in[l[:0:-1]+l for l in s[:0:-1]+s]:print''.join(['X'if n else' 'for n in l])