This is just where I will put random things that I think are interesting but don't really have a good place anywhere else on this website.
#define l(v)for(float v=-2;v<=2;v+=.1f)
int main(){l(i){l(r){float a=0,b=0;int v=16;while(v>0){float t=a*a-b*b+r;b=2*a*b+i;a=t;if(t*t+b*b>4)v=0;--v;}v?printf(".."):printf("##");}puts("");}}
I was bored one day and decided to waste some time trying to
code golf a C program that could output the Mandelbrot Set
to stdout. As far as I've tested, this compiles under
gcc 11.4.0
on Ubuntu.
Copy and paste the code and try it out yourself! :D
#define l for(i=2;i<N;i++)
int N=1000001,i,j;main(){int b[N];l b[i]=1;l{if(b[i]){printf("%d\n",i);for(j=i;j<N;j+=i)b[j]=0;}}}
This is a prime sieve written in C that outputs all the primes between
1 and 1000000 in only 126 bytes of source code. You can technically
shave off a few more bytes by removing the newline and instead
having a space be output (but reading the output is harder in
my opinion). Additoinally, you can shave off 2 more bytes by
removing the brackets from the if(b[i])
statement
so that only the printf
function is in the if statement.
The program still produces the same output but is slightly less
performant so I decided to keep the brackets. But technically
you can get this program down to 123 bytes. Additionally, you
can remove some digits from N to decrease the character count some
more. As far as I've tested, this compiles under gcc 13.3.0
on Ubuntu.