This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original idea by Mikkel Gjoel (https://computergraphics.stackexchange.com/a/5952/10515), | |
// simplified to one readable function. | |
// Demo at https://www.shadertoy.com/view/Wts3zH. | |
// Dithers and quantizes color value c in [0, 1] to the given color depth. | |
// It's expected that rng contains a uniform random variable on [0, 1]. | |
uint dither_quantize(float c, uint depth, float rng) { | |
float cmax = float(depth) - 1.0; | |
float ci = c * cmax; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple, defaultdict | |
EarleyItem = namedtuple("EarleyItem", ["rule", "dot", "origin"]) | |
def item_advance(item): | |
return EarleyItem(rule=item.rule, dot=item.dot + 1, origin=item.origin) | |
class Generator: | |
def __init__(self, G, terminals): | |
self.G = [["S'", G[0][0]]] + list(G) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sympy as sp | |
import itertools as it | |
from sympy.physics.quantum import TensorProduct | |
def companion_matrix(p): | |
"""Gives companion matrix for polynomial p.""" | |
p = sp.Poly(p) | |
assert p.is_monic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pattern-defeating quicksort | |
// Copyright Orson Peters 2017. | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See accompanying file LICENSE_1_0.txt or copy at | |
// http://www.boost.org/LICENSE_1_0.txt) | |
// See http://www.boost.org/libs/sort/ for library home page. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard, Hardcore, tmpstandard, tmphardcore | |
league = "tmpstandard" | |
categories = [ | |
"DivinationCards", | |
"Essence", | |
"UniqueMap", | |
"UniqueFlask", | |
"UniqueWeapon", | |
"UniqueArmour", | |
"UniqueMap", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#IfWinActive, Path of Exile ahk_class POEWindowClass | |
#MaxHotkeysPerInterval 500 | |
#SingleInstance force | |
SendMode Input | |
; Install the Fontin font http://www.exljbris.com/fontin.html. | |
; Edit log_file to your Client.txt path. | |
; Edit overlay_x, overlay_y to fit your desire. Default is right under the timer for 1920x1080. | |
; Your game needs to be in windowed fullscreen mode. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import sys | |
# We only use unicode in our parser, except for __repr__, which must return str. | |
if sys.version_info.major == 2: | |
repr_str = lambda s: s.encode("utf-8") | |
str = unicode | |
else: | |
repr_str = lambda s: s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy.ntheory import factorint, multiplicity | |
import operator as op, functools, itertools, fractions | |
factorlist = lambda n: sum(([p] * k for p, k in factorint(n).items()), []) | |
totient_factors = lambda n: sum((factorlist(p-1) + [p]*(k-1) | |
for p, k in factorint(n).items()), []) | |
divisors = lambda fs: [functools.reduce(op.mul, c, 1) | |
for l in range(len(fs) + 1) for c in itertools.combinations(fs, l)] | |
leadzero = lambda n, l: str(n).zfill(l) if l else "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bisect | |
import io | |
# We use 17-bit internal values with 15-bit probabilities. | |
CODE_VALUE_BITS = 17 | |
FP_MAX = (1 << CODE_VALUE_BITS) - 1 | |
FP_QUARTER = FP_MAX//4 + 1 | |
FP_HALF = 2*FP_QUARTER | |
FP_3QUARTER = 3*FP_QUARTER | |
FREQ_BITS = CODE_VALUE_BITS - 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import math | |
def prf_under_n(N, key, tweak): | |
b = math.ceil(math.log(N, 2)) | |
c = 0 | |
while True: | |
h = "" | |
while len(h) * 4 < b: |