Skip to content

Instantly share code, notes, and snippets.


jan grant jan-g

View GitHub Profile
View gist:2555e164003965aef8bdd8feb5469a06
This is an image!
# IMAGE: foo.jpg
+ restart?
-> END
jan-g /
Last active Feb 5, 2020
travesty, naive version and then an approach undreamt of back in 1984
#!/usr/bin/env python3
# Invoke with
# ./ {source-file} {n} {m}
# where {n} is the size of the n-gram used (3 for trigrams)
# {m} is the amount of output text required.
from collections import Counter
import os
from random import choice
View routines found in various infocom games
# 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
#!/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
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
View Python z3 session
# 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
View Bipartite graphs
#!/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.
View .git--hooks--pre-push
# This is based on the sample git pre-push hook script.
while read local_ref local_sha remote_ref remote_sha
jan-g /
Created Jan 30, 2018
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):
View digraph
#!/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"""
You can’t perform that action at this time.