###### tags: `I2P(I)Hu2022`
# 13628 - Elsa's curse
> by schdoel
## Brief
A snowflake of order n is composed of the character ‘#’ and spaces. In the middle is the largest square, aka 'central square.' In each corner is a snowflake of order n-1 whose central square touches the main central square in its corner, and in the middle of each edge is a snowflake of order n-2 whose central square touches the main central square on its edge.
These snowflakes are 1 pixel apart from each other. (Look at Figure 1 for reference)
The smallest snowflake is of size 1×1 pixel, aka. order 1 snowflake.
The snowflake with size 0, although not a snowflake, is called order 0 by convention.

## Solution
To help you with some math, we provide you with the code for generating the size of the middle square and the cumulative sum of the square sizes up to order 7, as well as the size of the snowflake. You can try to verify the code by yourself.
```cpp=
int middle[8] = {0,1};
int cumulative[8] = {0,1};
void initialize_size() {
for(int i = 2; i <= 7; i++) {
middle[i] = 4 * cumulative[i-2] - middle[i-2] + 2;
cumulative[i] = cumulative[i-1] + middle[i];
}
}
int snowflake_size(int order) {
return cumulative[order] + cumulative[order - 1];
}
```
## Reference Code
```cpp=
#include <stdio.h>
int middle[8] = {0,1};
int cumulative[8] = {0,1};
void initialize_size() {
for(int i = 2; i <= 7; i++) {
middle[i] = 4 * cumulative[i-2] - middle[i-2] + 2;
cumulative[i] = cumulative[i-1] + middle[i];
}
}
int size(int deg) {
return cumulative[deg] + cumulative[deg - 1];
}
char func(int x, int y, int deg) {
if(deg == 0) return ' ';
if(deg == 1) {return (x == 0 && y == 0)? '#': ' ';}
else {
if (x > size(deg)/2) x = size(deg) - x - 1;
if (y > size(deg)/2) y = size(deg) - y - 1;
if(x >= cumulative[deg-1] && y >= cumulative[deg-1]) return '0' + deg;
if(x + y >= 2 * cumulative[deg - 1] - 1) {
int _y = y;
y = 2 * cumulative[deg - 1] - x - 1;
x = 2 * cumulative[deg - 1] -_y - 1;
}
return func(x, y, deg - 1);
}
}
int main() {
initialize_size();
int n;
scanf("%d", &n);
for(int i = 0; i < size(n); i++) {
for(int j = 0; j < size(n); j++) {
printf("%c", func(i,j,n));
}
printf("\n");
}
}
```