Migrated from private repo

This commit is contained in:
2023-12-18 21:37:02 +01:00
parent 9ba14b2f44
commit 3f5025d68c
11 changed files with 317 additions and 0 deletions

Binary file not shown.

1
sierpinski/no_code.md Normal file
View File

@ -0,0 +1 @@
The code is lost unfortunately, but we didn't have this in the slides anyway for obvious reasons though.

42
sierpinski/triangle.c Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#define SIZE 32 // Size of the grid
void sierpinski(int x, int y, int size, char grid[SIZE][SIZE]) {
if (size == 1) {
grid[y][x] = '*';
return;
}
int subSize = size / 2;
// Top triangle
sierpinski(x, y, subSize, grid);
// Bottom left triangle
sierpinski(x - subSize, y + subSize, subSize, grid);
// Bottom right triangle
sierpinski(x + subSize, y + subSize, subSize, grid);
}
int main() {
char grid[SIZE][SIZE];
memset(grid, ' ', sizeof(grid));
sierpinski(SIZE / 2, 0, SIZE / 2, grid);
// Calculate the height of the triangle and print only the necessary rows
int height = (int)(0.866 * SIZE / 2);
for (int i = 0; i <= height; i++) {
for (int j = 0; j < SIZE; j++) {
printf("%c", grid[i][j]);
}
printf("\n");
}
return 0;
}