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 enum import IntFlag, auto | |
class Colour(IntFlag): | |
R = auto() # When the class is defined, this'll get the value 1 | |
G = auto() # ... and 2 | |
B = auto() # ... and 4, and so on | |
Cyan = G | B # You can construct combinations inside the class definition | |
def is_blue(self): | |
return (self & Colour.B) != 0 |
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
# pip install z3-solver | |
from z3 import * | |
s = Solver() | |
w = Int('w') | |
m = Int('m') | |
s.add(0 <= m, m <= 12) | |
s.add(0 <= w, w <= 12 - m) | |
s.add(m / Q(2,1) + w / Q(4,1) + 2 * (12 - m - w) == 12) # Q(a,b) is the rational a/b |
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
#!/usr/bin/env python | |
from collections import defaultdict | |
def bipartite(*pairs): | |
"""Construct a bipartition of nodes | |
The input is a series of pairs of nodes that must be in different disjoint sets. |
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
#!/bin/sh | |
# This is based on the sample git pre-push hook script. | |
remote="$1" | |
url="$2" | |
z40=0000000000000000000000000000000000000000 | |
while read local_ref local_sha remote_ref remote_sha |
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
#!/usr/bin/env python3 | |
import random | |
import collections | |
# t is a map of n -> count, where n is the size of the repeat, and count is the | |
# number of rolls that fall into that category | |
t = collections.Counter() | |
for r in range(1, 100000): |
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
#!/usr/bin/env python3 | |
import collections | |
import argparse | |
import itertools | |
def load_ngraphs(fn, n): | |
"""Load in a set of ngraph counts from a source corpus""" |
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
% iex | |
Erlang/OTP 18 [erts-7.3.1.2] [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false] | |
Interactive Elixir (1.2.6) - press Ctrl+C to exit (type h() ENTER for help) | |
iex(1)> c("priority.ex") | |
hello.ex:1: warning: redefining module MyPriority | |
[MyPriority] | |
iex(2)> MyPriority.run | |
running | |
in main loop |
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
rows 25 | |
1 1 2 2 | |
5 5 7 | |
5 2 2 9 | |
3 2 3 9 | |
1 1 3 2 7 | |
3 1 5 | |
7 1 1 1 3 | |
1 2 1 1 2 1 | |
4 2 4 |
NewerOlder