Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,13 @@
#include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}

View file

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#ifndef _POSIX_C_SOURCE
char *strdup(const char *s)
{
int l = strlen(s);
char *r = malloc(l+1);
memcpy(r, s, l+1);
return r;
}
#endif
#define truth(X) ((X)=='*'?true:false)
void rule_90(char *evstr)
{
int i;
int l = strlen(evstr);
bool s[3];
char *cp = strdup(evstr);
for(i=0;i < l; i++) {
s[1] = truth(cp[i]);
s[0] = (i-1) < 0 ? false : truth(cp[i-1]);
s[2] = (i+1) < l ? truth(cp[i+1]) : false;
if ( (s[0] && !s[2]) || (!s[0] && s[2]) ) {
evstr[i] = '*';
} else {
evstr[i] = ' ';
}
}
free(cp);
}

View file

@ -0,0 +1,18 @@
void sierpinski_triangle(int n)
{
int i;
int l = 1<<(n+1);
char *b = malloc(l+1);
memset(b, ' ', l);
b[l] = 0;
b[l>>1] = '*';
printf("%s\n", b);
for(i=0; i < l/2-1;i++) {
rule_90(b);
printf("%s\n", b);
}
free(b);
}

View file

@ -0,0 +1,5 @@
int main()
{
sierpinski_triangle(4);
return EXIT_SUCCESS;
}