Skip to content

Instantly share code, notes, and snippets.

@kevinastock
kevinastock / spell_check.py
Created November 3, 2019 00:13
Spell Checker
"""Spelling Corrector.
Copyright 2010 Kevin Stock
Open source code under MIT license: http://www.opensource.org/licenses/mit-license.php
Derived from http://norvig.com/spell.py
Prunes the search space by only performing edits that are valid while walking a prefix trie.
"""
import re, collections
@kevinastock
kevinastock / sudokusat.py
Created November 2, 2019 23:33
Sudoku SAT solver
#!/usr/bin/env python3
# A 3x3 puzzle:
# .....2....2......66..5...8...3..9...89..37..1........7....239.87.2.6.5...........
import argparse
import math
import random
import subprocess
import sys
# ---------- Primitives -----------------
def circle(r=None, d=None):
return _base_object("circle", r=r, d=d)
def square(*args, center=True):
if len(args) == 1:
size = str(args[0])
elif len(args) == 2:
size = str(args)
@kevinastock
kevinastock / kspopt.js
Created July 25, 2014 07:40
KSP single stage optimizer in js
"use strict";
function Part(name, size, deadend, cost, mass, fuel, thrust, iatm, ivac, gimbal, cost_save) {
this.name = name;
this.size = size;
this.deadend = deadend;
this.cost = cost;
this.mass = mass;
this.fuel = fuel;
this.thrust = thrust;
@kevinastock
kevinastock / kspopt.py
Last active August 29, 2015 14:04
Find optimal engines & tanks for a single stage
#!/usr/bin/env python3
from collections import namedtuple
from itertools import combinations_with_replacement, groupby
import math
import operator
# FIXME: ban engines over certain length
# FIXME: ban 1x of any engine
@kevinastock
kevinastock / gist:2495625
Created April 26, 2012 03:45
DCPU Hardware test program
; define where the screen is
:screen .equ 0x8000
; i : hardware id counter
set i, 0
hwn j
:setup ; inspect all connected devices, setup recognized ones
ife i, j
set pc, main
@kevinastock
kevinastock / gist:2430330
Created April 20, 2012 17:08
Implementation of quicksort
; Quicksort
;
; Jump to qsort w/ A at first element and B at last
; A - start
; B - end
; X - pivot
; Y - swap temp