Skip to content

Instantly share code, notes, and snippets.

#include <pulse/simple.h>
#include <pulse/error.h>
#include <array>
#include <stdexcept>
#include <memory>
#include <iostream>
#include <complex>
#include <functional>
#include <GLFW/glfw3.h>
#include <fftw3.h>
import random
def draw_hand():
hand = set()
while len(hand) < 8:
hand.add(random.randrange(40000))
return list(hand)
def encode_perm(l, x):
l = list(l)
# Copyright 2020 Jannis Harder
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
@jix
jix / unitri.py
Last active March 10, 2024 09:18
# Copyright 2020 Jannis Harder
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
import networkx as nx
import itertools
def transitive_closure_compression(g):
# For a given DAG return a smaller (edge count) DAG with additional nodes
# and a transitive closure that has the transitive closure of the original
# DAG as induced subgraph.
# It does this by generating a contraction hierachy (CH) and building a new
#!/usr/bin/env python3
import os
import sys
argv = sys.argv[1:]
try:
pkg_name = os.environ['CARGO_PKG_NAME']
except KeyError:
pass
@jix
jix / README.md
Last active August 29, 2015 14:02 — forked from mbostock/.block

Wilson’s algorithm uses loop-erased random walks to generate a uniform spanning tree — an unbiased sample of all possible spanning trees. Most other maze generation algorithms, such as Prim’s, random traversal and randomized depth-first traversal, do not have this beautiful property.

The algorithm initializes the maze with an arbitrary starting cell. Then, a new cell is added to the maze, initiating a random walk (shown in magenta). The random walk continues until it reconnects with the existing maze (shown in white). However, if the random walk intersects itself, the resulting loop is erased before the random walk continues.

Initially, the algorithm can be frustratingly slow to watch, as the early random walks are unlikely to reconnect with the small existing maze. However, as the maze grows, the random walks become m