Skip to content

Instantly share code, notes, and snippets.

View milesrout's full-sized avatar

Miles Rout milesrout

View GitHub Profile
def attempt(f, is_valid, *args):
return next(y for y in itertools.starmap(f, itertools.repeat(args)) if is_valid(y))
@milesrout
milesrout / cons.py
Last active September 7, 2016 11:30
def lazy_any(*args):
for arg in args:
if bool(arg()):
return True
return False
def is_self_evaluating_term(obj):
return lazy_any(
lambda: is_primitive_data(obj),
lambda: is_primitive_operative(obj),
def vau(ptree, env):
t1, s, t2 = ptree
fv = set.union(
t2.free_variables(),
env.free_variables())
if s is Ignore:
c, env1, _ = definiend(t1, fv)
return c.subst(evaluate(t2, concat_envs(env1, env)))
else:
x, X = make_distinct_var(fv)
template<typename... Args>
bool all(Args... args) { return (... && args); }
bool b = all(true, true, true, false);
// within all(), the unary left fold expands as
// return ((true && true) && true) && false;
// b is false
using cons = struct {
template <typename car>
struct value {
struct type {
template <typename cdr>
using of = cons_literal<car, cdr>;
};
};
template <typename car>
def enumerate_vs(S, G):
"""Enumerate all hypotheses contained in the version space bounded by S and G."""
hypotheses = set()
for s in S:
for g in G:
places = [i for i in range(len(s)) if s[i] != g[i]]
for ss in all_subsets(places):
conj = Conjunction(g[i] if (i in ss) else s[i] for i in range(len(s)))
hypotheses.add(conj)
return hypotheses
def calc(roll, miss, crit, dodge, parry, hit):
roll += hit
roll -= parry
if roll < 0.0:
return 'parry'
roll -= dodge
if roll < 0.0:
return 'dodge'
roll -= miss
if roll < 0.0:
from copy import copy, deepcopy
import functools
import itertools
import operator
class Attribute(tuple):
pass
class Instance(tuple):
pass
import argparse
import os
import random
import shutil
def safe_mkdir(*args, **kwds):
try:
return os.mkdir(*args, **kwds)
except FileExistsError:
pass