STEAM GROUP
Kickass Programmers quprogs
STEAM GROUP
Kickass Programmers quprogs
3
IN-GAME
11
ONLINE
Founded
November 6, 2015
Language
English
Showing 1-10 of 22 entries
11
How bad is your keyboard?
7
Code Golf -- Don't Google "Google"
1
Code Golf -- Implement Bogosort
11
How bad is your keyboard?
4
Code Golf -- Print N Squared
1
Code Golf -- Read a crossword
4
Code Golf -- Print N Squared
C++14, 156 chars
#define f for(i=0;i++<n;c<<t); [](string t){auto&c=cout;int n=stoi(t),i;f c<<'\n';for(i=0;++i<n-1;c<<t,c.width(~-n*size(t)+1),c.fill(0),c<<t+'\n');if(n-1)f}

This one is pretty cool though it took a long time of fidgeting to get it to work. Unpacked:
#define f for ( i = 0; i++ < n; c << t ); [](string t) { auto& c = cout; int n = stoi(t), i; f // print first row c << '\n'; // kind of annoying but no way to get rid of (yes I tried // c << '\n'+t instead of c << t+'\n') for ( i = 0; ++i < n - 1; ) { c << t; // output the number // then we we get the width of necessary spaces c.width(~-n*size(t)+1); // Equivalent to (n-1)*size(t) + 1, but we save // two characters because ~- takes precedence over // the multiplication c.fill(0); // fill with spaces, ' ' == 0 c << t+'\n'; } if ( n-1 ) f // This if statement is dissapointing }

And like always... to run it you need to use [](string t) { ... }("10");

C++14, 162 chars
The above was my first attempt at the solution and took about 20 minutes. This next one took close to an hour, but unfortunately was not as good as my first attempt. It's a lot more sane, but 6 more chars, if it were not for edge cases 1 & 0 this could match my first solution. I figured I'd post it anyways since I spent so much time on it.
#define f for(i=-2;i++<n;c<<t);c<<'\n'; [](string t){auto&c=cout;int n=stoi(t)-2,i;auto g=t;g.append(abs(n)*size(t),' ');g+=t+'\n';f;for(i=0;i++<n;c<<g);if(n+1)f;}

and unpacked:

[](string t) { auto&c = cout; int n = stoi(t)-2,i; auto g = t; // creating "num ... num" // this abs(n) is very unfortunate, blame edge cases 1 & 0 g.append(abs(n)*size(t),' '); g += t+'\n'; f; for ( i = 0; i++ < n; c << g); if ( n+1 ) f; }
Showing 1-10 of 22 entries