Skip to content

Instantly share code, notes, and snippets.

Avatar

Marlon Etheredge ofx

  • The Netherlands
View GitHub Profile
View Subset Sum
#include <math.h>
#include <stdio.h>
int S[] = {-7, -3, -2, 5, 8};
int main()
{
unsigned int i, n, a, j, nn, ui;
n = pow(2, sizeof(S) / sizeof(int)) - 1;
ui = sizeof(S) / sizeof(int);
@ofx
ofx / gist:f3b28f5765b5a7d8edc3
Created Mar 17, 2015
Build a kd-tree for 2d points, with two consecutive x-levels and one y-level.
View gist:f3b28f5765b5a7d8edc3
#!/usr/bin/python
import sys
import numpy
import Queue
import numpy as np
import random
import matplotlib.pyplot as plt
View Lens distortion GLSL
float k1 = 0.0;
float k2 = 0.0;
float k3 = 0.0;
float p1 = 0.0;
float p2 = 0.0;
const int lk = 12;
void mainImage( out vec4 fragColor, in vec2 fragCoord )
View git submodule rm
#!/bin/bash
if [ "$1" != "" ]; then
git submodule deinit -f -- $1
rm -rf .git/modules/$1
git rm -f $1
fi
@ofx
ofx / collatz.cpp
Last active Mar 29, 2018
Collatz Conjecture
View collatz.cpp
#include <iostream>
#include <ctime>
#include <tuple>
constexpr const std::tuple<unsigned long, unsigned long> max(const unsigned int a, const unsigned int b)
{
const auto c = [](auto&& s, const unsigned long n) constexpr -> const unsigned int {
if (n == 1) return 1;
return 1 + s(s, n % 2 ? n * 3 + 1 : n / 2);
};
View bc.py
import sys
# Constants
OPERATORS = ['*', '/', '+', '-']
DECIMAL_SYMBOLS = [',', '.']
SIGN_SYMBOLS = ['-', '+']
PARENTHESIS_OPEN = '('
PARENTHESIS_CLOSE = ')'
PRECEDENCE = [[PARENTHESIS_OPEN], ['*', '/'], ['+', '-']]
@ofx
ofx / threadpool.c
Created Aug 18, 2018
Old threadpool implementation (pthread)
View threadpool.c
//
// threadpool.c
// threadpool
//
#include "threadpool.h"
static void *sweep(void *voidtask)
{
task *task = voidtask;
View convert_n_based_numbersystem.py
def convert(x, N):
y = x % N
x = x // N
if (x == 0):
return [y]
else:
return convert(x, N) + [y]
print(convert(10001, 16))
@ofx
ofx / alu16.cpp
Last active Nov 10, 2018
16-bits ALU
View alu16.cpp
#include <assert.h>
#include <bitset>
#include <iostream>
#include <limits>
#include <random>
#define ALU_ADD 0
#define ALU_SUB 1
#define ALU_AND 2
#define ALU_OR 3
View bitfield.cpp
#include <array>
#include <assert.h>
#include <bitset>
#include <iostream>
#include <limits.h>
#include <ostream>
template <size_t N> class bitfield : public std::bitset<N> {
public:
bitfield(std::array<unsigned char, N / CHAR_BIT> bytes)