"blind" programming [challenge]
Name:
Anonymous
2015-04-29 23:33
Here's a stupid idea.
You know things like "print this pattern:
*
***
*****
*******
*********
can be done wiht any dumb challenges like this..
try to solve it by writing the program into this thread - NO TESTING! Then try it out.
Name:
Anonymous
2015-04-30 0:10
This is in C,
#include <stdio.h>
#include <string.h>
// N >= 1
#define N 5
void f(char *s, size_t n)
{
size_t i;
for(i = 0; i < n; i++)
if(s[i] == '*') s[i-1] = s[i+1] = '*';
}
int main() {
char s[2*N] = {0};
memset(s, ' ', sizeof s - 1);
s[sizeof s / 2 - 1] = '*';
for(puts(s); *s != '*'; puts(s))
f(s);
return 0;
}
Name:
Anonymous
2015-04-30 0:46
C, the X version
#include <stdio.h>
// N => 1
#define N 5
int main() {
int i, j;
char s[64], out[2*N] = {0};
for(i = 0; i < 2*N - 1; i++) {
for(j = 0; j < 2; j++) {
sprintf(s, "%%.%ds%%c", i + 2*j*(N - i - 1));
sprintf(out, s, '*');
}
puts(out);
}
return 0;
}
Name:
Who am I quoting?
2015-04-30 4:56
#include <stdio.h>
void
pyramid(int width, int level)
{
int stars = (2 * level) + 1;
int spaces = (width - stars) / 2;
if(stars > width)
return;
while(spaces--)
puts(' ');
while(stars--)
puts('*');
puts('\n');
pyramid(width, level + 1);
}
int
main(void)
{
pyramid(9, 0);
return 0;
}
Newer Posts