Skip to content

Instantly share code, notes, and snippets.

@nightuser
nightuser / torus_interpolation.py
Last active August 29, 2015 14:11
Torus topology interconnection interpolation
import itertools
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import Delaunay
points = np.array([
[0, 0],
[0, 2],
[2, 0],
[0.5, 0.5]
/*
Dependencies: LAPACK
Ubuntu: sudo apt-get install liblapack3 liblapack-dev
Compile: g++ -o barycentric barycentric.cpp -O3 -Wall -Wextra -pedantic -std=gnu++11 -llapack
*/
#include <iostream>
#include <cassert>
@nightuser
nightuser / toroidal.R
Last active August 29, 2015 14:12
Toroidal (R)
toroidal <- function(points, values) {
d <- ncol(points)
shifts <- sapply(
1:d,
function(x) { max(points[, x]) - min(points[, x]) }
)
directions <- c(0, 1, -1)
all_shifts <- expand.grid(
lapply(
@nightuser
nightuser / test1.py
Last active August 29, 2015 14:18
Sympy bad performance with polynomials
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from sympy import Poly, Symbol
from scipy.signal import fftconvolve
x = Symbol('x')
k = 19937
@nightuser
nightuser / hw04.py
Last active August 29, 2015 14:21
HW04: Convex polygon with random order
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from functools import cmp_to_key
from pylab import *
from scipy import stats
def standard_simplex_draw_point(n):
@nightuser
nightuser / wiener.py
Created May 25, 2015 21:10
HW05: Wiener process
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import bisect
import numpy as np
from functools import total_ordering
from numpy.random import normal
from pylab import *
@nightuser
nightuser / main.cpp
Last active March 21, 2016 00:34
Incomplete long arithmetics
#include <algorithm>
#include <iostream>
#include <vector>
#include <csignal>
using std::cout;
using std::endl;
using vint = std::vector<int>;
int const kBase = 100;
@nightuser
nightuser / optional_deps.py
Created April 14, 2022 16:37
Gentoo: list optional dependencies for installed packages
#!/usr/bin/env python3
import re
import portage
import shlex
optfeature_re = re.compile(r'optfeature\s+(.*)$')
packages = portage.db[portage.root]['vartree'].dbapi.cpv_all()
@nightuser
nightuser / main.py
Created February 22, 2015 19:12
Simple Lehmer random number generator and Pi calculus. No NumPy, pure Python only.
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
from functools import reduce
from math import sqrt
from random import random
class MyRandomizer:
@nightuser
nightuser / bbs_crack.py
Last active November 28, 2022 16:12
Blum-Blum-Shub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sympy import pollard_rho
from sympy.core.numbers import igcd
from sympy.ntheory import sqrt_mod, nthroot_mod, isprime, factorint
from sympy.ntheory.modular import crt
with open('bbs.txt', 'r') as f:
xs = [int(x.rstrip()) for x in f.readlines()]