Skip to content

Instantly share code, notes, and snippets.

View jan-g's full-sized avatar

jan grant jan-g

  • UTC
View GitHub Profile
@jan-g
jan-g / Difficult
Last active December 15, 2015 10:58
Nonograms.
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
@jan-g
jan-g / ZZZ console session
Last active March 1, 2017 14:48
"Priority" mailbox implementation (from Seven Chapters and Matt's Trousers in Some Weeks)
% 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
@jan-g
jan-g / digraph
Created April 26, 2017 14:12
Anagrams
#!/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"""
@jan-g
jan-g / monty.py
Created January 30, 2018 15:38
monte carlo for Alex
#!/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):
@jan-g
jan-g / .git--hooks--pre-push
Created September 27, 2018 10:31
pre-push hook
#!/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
#!/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.
# 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
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
#!/usr/bin/env python3
# From the introduction, pp. 5-6.
# Two approaches to generate anagrams.
from collections import Counter
from functools import cmp_to_key
from math import log2, factorial
from string import ascii_lowercase # not very internationally-minded, but it'll do for these purposes
# This is a poor approximation at looking for the history of implementations as they were copied between games.
# Although various things might have a similar routine (OWN-FEET, for instance), it's clear that these all underwent
# change as the basic parser grew more capabilities.
A-AN planetfall planetfall-gold
A-O-K seastalker
A-PRSI lurkinghorror spellbreaker
A-PRSI? lurkinghorror spellbreaker
A-PRSO lurkinghorror spellbreaker