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
  • 00:43 (UTC -04:00)
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct iris_dataset_struct
{
double inputs[4];
double output[3];
} iris_dataset_holder;
iris_dataset_holder iris_dataset_holder_array[ ] =
@MurageKibicho
MurageKibicho / Baseconverter.c
Created February 14, 2025 07:06
Convert from base 10 to an arbitrary base
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double LogN(double number, int base)
{
return log((double)number) / log((double)base);
}
void Base10ToBaseN(int number, int base, int *baseLength, int **baseHolder)
{
@MurageKibicho
MurageKibicho / BlankinshipGMP.c
Created February 14, 2025 18:04
Blankinship's algorithm but for big integers in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <gmp.h>
//Run command : clear && gcc BlankinshipGMP.c -lgmp -lm -o m.o && ./m.o
typedef struct blankinship_row_struct *BlankinshipRow;
typedef BlankinshipRow* BlankinshipMatrix;
struct blankinship_row_struct
@MurageKibicho
MurageKibicho / Blankinship.c
Created February 14, 2025 18:07
Blankinship's algorothm for integers
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
typedef struct blankinship_row_struct *BlankinshipRow;
typedef BlankinshipRow* BlankinshipMatrix;
struct blankinship_row_struct
{
int leader;
int numberOfColumns;
@MurageKibicho
MurageKibicho / Generator.c
Created March 2, 2025 16:43
Find Generators of a fiel mod a prime number in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Function to compute (base^exp) % mod using fast modular exponentiation
long long mod_exp(long long base, long long exp, long long mod) {
long long result = 1;
while (exp > 0) {
if (exp % 2 == 1) result = (result * base) % mod;
base = (base * base) % mod;
@MurageKibicho
MurageKibicho / Test2PrimitiveRoot.c
Last active March 3, 2025 08:32
Check if 2 is a primitive root in gf(p)
//Code from this Murage Kibicho answer on Stack Exchange : https://math.stackexchange.com/questions/3260673/primes-having-2-as-a-primitive-root/5041497#5041497
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
int ModularExponentiation(int base, int exp, int mod)
{
@MurageKibicho
MurageKibicho / fp.c
Created March 19, 2025 12:11
FixedPoint
// Online C compiler to run C program online
#include <stdio.h>
#include <stdint.h>
typedef int64_t fixedpt;
#define FIXEDPT_BITS 32
#define FIXEDPT_WBITS 24
#define FIXEDPT_FBITS (FIXEDPT_BITS - FIXEDPT_WBITS)
#define FIXEDPT_ONE ((fixedpt)((fixedpt)1 << FIXEDPT_FBITS))
#define fixedpt_rconst(R) ((fixedpt)((R) * FIXEDPT_ONE + ((R) >= 0 ? 0.5 : -0.5)))
@MurageKibicho
MurageKibicho / Posit.c
Created March 20, 2025 12:20
Signed Residue number system
#ifndef _FFASM_H_
#define _FFASM_H_
#ifndef ff_BITS
#define ff_BITS 32
#endif
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
@MurageKibicho
MurageKibicho / gist:b6520c6f66325fe13f6de47cd35e3454
Created March 21, 2025 17:52
Noise Schedules for Diffusion Models in C
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#define PI 3.14159265358979323846
#define MIN_BETA 0.0001
#define MAX_BETA 0.9999
float DiffusionInternalSigmoid(float x)
@MurageKibicho
MurageKibicho / Diffusion.c
Created March 22, 2025 03:48
Forward step Diffusion
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#define PI 3.14159265358979323846
#define MIN_BETA 0.0001
#define MAX_BETA 0.9999
float DiffusionInternalSigmoid(float x)