Она - балансирует на грани "сделать, не делая полноценный парсер грамматик"
void DrawCurve(char* output, int stride, int order) {
if (order == 0) {
output[0] = output[stride+1] = '/';
output[1] = output[stride] = '\\';
return;
}
int sz = (3 << (order - 1)) - 1;
DrawCurve(output, stride, order-1);
DrawCurve(output+(sz+1)*stride, stride, order-1);
DrawCurve(output+sz+1, stride, order-1);
DrawCurve(output+(sz+1)*stride+sz+1, stride, order-1);
output[(sz-1)*stride+sz-1] = ' ';
output[(sz+1)*stride+sz-1] = ' ';
output[(sz-1)*stride+sz+1] = ' ';
output[(sz+1)*stride+sz+1] = ' ';
for (int i = 0; i < 2*sz+1; ++i) {
output[i*stride + sz] = output[sz*stride + i] = ' ';
}
output[sz*stride+sz-1] = '[';
output[sz*stride+sz+1] = ']';
output[(sz-2)*stride+sz] = '_';
output[(sz+1)*stride+sz] = '_';
}
int main()
{
const int order = 3;
const int stride = 3 << order ;
const int height = (3 << order) - 1;
char field[stride*height];
memset(field, 0, sizeof(field));
DrawCurve(field, stride, order);
for (int i = 0; i < height; ++i) {
cout << field + i*stride << "\n";
}
return 0;
}
#357 = CIRCLE ( 'NONE', #49, 20.00000000000000355 ) ;
import itertools
def Gen(s, k, m, cur): # разбить S на K слагаемых от 1 до M
if m == 1:
if s != k: return
new_list = list(cur)
new_list.extend([1]*k)
yield from set(itertools.permutations(new_list))
#yield new_list # если порядок не важен
return
can_fit = min(s//m, k, (s-k)//(m-1))
need_take = max(0, s-k*(m-1))
new_list = list(cur)
new_list.extend([m]*need_take)
for i in range(need_take, can_fit+1):
yield from Gen(s-m*i, k-i, m-1, new_list)
new_list.append(m)
print(Gen(227, 52, 7, []))