Skip to content

Instantly share code, notes, and snippets.

View MurageKibicho's full-sized avatar
🛼
Working from home

Murage Kibicho MurageKibicho

🛼
Working from home
  • Yale University
  • New Haven, Connnecticut
  • 04:31 (UTC -04:00)
View GitHub Profile
@MurageKibicho
MurageKibicho / FirstPrimeFactor.c
Created July 22, 2025 01:19
Find the first prime factor of n
int FirstPrimeFactor(int n)
{
if(n == 0 || n == 1)
{
return n; // 0 and 1 have no prime factors
}
if(n < 0)
{
n = -n; // Work with absolute value
}
@MurageKibicho
MurageKibicho / FindCubeInPrimeFactorization.c
Created July 22, 2025 01:15
Test for the largest cubic prime factor
// Online C compiler to run C program online
#include <stdio.h>
int FindCubeInPrimeFactorization(int n)
{
if (n == 0) return 0; // 0³ = 0
if (n == 1) return 1; // 1³ = 1
int cube = 1;
for(int p = 2; p * p <= n; p++)
{
@MurageKibicho
MurageKibicho / ConicPlot.c
Created July 20, 2025 12:21
Function to solve conic equation y in terms of x
//Full derivation here: https://leetarxiv.substack.com/p/conic-sections-matrix-theory
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
typedef struct{ double x, y; }Point;
//Run: clear && gcc ConicPlot.c -lm -o m.o && ./m.o
// Solve conic equation for y given x
bool GetConicPoints(double A, double B, double C, double F, double G, double H, double x, Point* y1, Point* y2)
{
@MurageKibicho
MurageKibicho / ConicIdentify.c
Created July 20, 2025 09:41
C Function to Identify Conic Sections by Matrix Form
//Code Explained : https://leetarxiv.substack.com/p/conic-sections-matrix-theory
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#define COMPARE_EPSILON 1e-6f
#define INDEX(x, y, cols) ((x) * (cols) + (y))
typedef enum matrix_type_enum MatrixType;
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <SDL.h>
#include <SDL_opengles2.h>
#else
#include <SLD2/SDL.h>
#include <SDL2/SDL_opengles2.h>
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
@MurageKibicho
MurageKibicho / TextureCamera2.c
Created July 17, 2025 15:06
Texture camera second step
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <SDL.h>
#include <SDL_opengles2.h>
#else
#include <SLD2/SDL.h>
#include <SDL2/SDL_opengles2.h>
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
@MurageKibicho
MurageKibicho / Safetensors.c
Created July 15, 2025 14:55
Opening a Safetensors file in C
//Written guide to this code available here: https://leetarxiv.substack.com/p/parsing-safetensors-file-format
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <sys/mman.h>
#include <stdbool.h>
#include "Dependencies/cJSON.h"
@MurageKibicho
MurageKibicho / Wu.c
Created July 12, 2025 12:24
Wu's Line Drawing Algorithm in C
//Full description: https://leetarxiv.substack.com/p/an-efficient-anti-aliasing-technique
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
typedef struct point_struct Point;
typedef uint32_t RGBA;
@MurageKibicho
MurageKibicho / main.c
Created July 12, 2025 11:27
Starter code for Wu's line-drawing algorithm
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
typedef struct point_struct Point;
typedef uint32_t RGBA;
struct point_struct
@MurageKibicho
MurageKibicho / GMPCompositions.c
Created July 12, 2025 06:59
Using LibGMP to enumerate integer compositions
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
#include <gmp.h>
#include <assert.h>
#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"
//clear && gcc Nichols.c -lm -lgmp -o m.o && ./m.o