Skip to content

Instantly share code, notes, and snippets.

View vanaur's full-sized avatar
🐿️
I enjoy squirrels

vanaur

🐿️
I enjoy squirrels
View GitHub Profile
@vanaur
vanaur / UnionFind.fs
Created April 9, 2024 12:48
This module implements a generic union-find data structure in F# (for .NET)
/// This module implements a generic [union-find](https://en.wikipedia.org/wiki/Disjoint-set_data_structure) data structure.
/// This structure is used to manage disjoint sets, often used in partitioning or clustering problems.
///
/// Here is a summary of the features and members of this data structure:
///
/// 1. **Constructor**: The `UnionFind` constructor initializes a new instance of the Union-Find data structure with
/// default elements of the original set specified as a sequence. This set can be extended.
///
/// 2. **Public Members** :
/// - `UnionFind.AddElement` Adds a new element to the set.
@vanaur
vanaur / ColumnParser.fsx
Created June 29, 2022 14:33
Parse a file of spaced columns
#r "nuget: FParsec, 1.1.1"
open FParsec
let ws = skipMany (pchar ' ' <|> pchar '\t')
let ws1 = skipMany1 (pchar ' ' <|> pchar '\t')
let parseComment =
pstring "#" >>. skipRestOfLine true >>% []
typedef struct stack_s
{
long sz;
long sp;
void **s;
} *stack_t;
#define stack_pop(__t,__s) ((__t)_stack_pop(__s))
#define stack_peek(__t,__s) ((__t)_stack_peek(__s))
#define stack_is_empty(_s) (_s->sp == -1)
typedef struct pool_s
{
char *next;
char *end;
} pool_t;
pool_t *pool_create(const size_t sz)
{
pool_t *p = malloc(sz + sizeof *p);
assert(p != NULL);
@vanaur
vanaur / Makefile
Last active September 13, 2022 18:09
Generic makefile for C projects that follow the "app" + "include" + "source" configuration.
# Defines which shell command to use to clean the terminal, depending on the platform.
ifeq ($(OS), Windows_NT)
# Clean on Windows
clean_cmd = @del /s /q *.o > null
else
# Clean on UNIX systems
clean_cmd = @rm -f *.o
endif
# A recursive function that allows to list all files with a given extension, in folders and sub-folders, from a given source.
@vanaur
vanaur / main.c
Created June 6, 2020 18:34
Very small JIT with constant program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include "mman.h"
#else
#include <sys\mman>
#endif
// This simple JIT program just returns the user input number
# riddle-of-100-prisoners
import numpy as np
import random
def algo(number):
midl = int((number / 2) - 1)
boxes = np.arange(number)
random.shuffle(boxes)