Skip to content

Instantly share code, notes, and snippets.

/* two barrels problem */
/* works on get(3, 5, 2). fails on get(3, 2, 5). overflow on get(100, 5, 2).
*/
/* pour from barrel containing X1 to barrel
* containing Y1 with capacity Ycap,
* giving barrels containing X2 and Y2
*/
pour(X1, Y1, Ycap, X2, Y2) :-
X1 > 0,
@dmoney
dmoney / fizzbuzz.sh
Created May 10, 2013 01:57
Script for verifying the output of a FizzBuzz program. $ ./fizzbuzz.sh | ./fizzcheck.sh $ ./fizzcheck.sh ./fizzbuzz.sh`
#!/bin/sh
# fizzbuzz.sh - A reference FizzBuzz program for testing fizzcheck.sh
# Author: Dustin King ([email protected])
limit=20
i=1
while expr $i '<=' $limit >/dev/null; do
out=
if expr $i % 3 = 0 >/dev/null; then out=Fizz; fi
@dmoney
dmoney / gist:6836237
Last active December 24, 2015 17:29 — forked from anonymous/gist:6836227
// my solution to exercise 5 of "you can't javascript under pressure"
// http://toys.usvsth3m.com/javascript-under-pressure/
function arraySum(i) {
// i will be an array, containing integers, strings and/or arrays like itself.
// Sum all the integers you find, anywhere in the nest of arrays.
var sum = 0;
var counter = 0;
var stack = [];
var call=false;
#!/usr/bin/perl
use strict;
use warnings;
# columnStats.pl
# A script to count lines of comma-separated input, grouped by some column value.
#
# Author: Dustin King ([email protected])
#
# Usage: perl columnStats.pl [COLNUM]
# allinomial.py
# Author: Dustin King ([email protected])
#
# This is my answer to the problem presented here:
# http://www.leighhalliday.com/solution-software-engineer-interview-challenge
#
# """ Write a program that outputs all possibilities to put + or -
# or nothing between the numbers 1, 2, ..., 9 (in this order)
# such that the result is always 100.
# For example: 1 + 2 + 34 - 5 + 67 - 8 + 9 = 100. """
# sentence_diagram.pseu.py
# A doodle in sentence diagramming using Python.
# Author: Dustin King ([email protected], twitter.com/cathodion)
#
# By "doodle" I mean not actually functional, but if this
# sentence diagramming library existed, this is what part of
# a client program would look like.
#
# Based on the example sentence and diagram given at:
# http://www.npr.org/sections/ed/2014/08/22/341898975/a-picture-of-language-the-fading-art-of-diagramming-sentences
import unittest
TREE = (1, (2, None, None), (3, (4, None, None), (5, None, None)))
EXPECTED_REVERSED = (1, (3, (5, None, None), (4, None, None)), (2, None, None))
def reversed(tree):
if tree is None:
return None
else:
val, left, right = tree
'''Streaming pickle implementation for efficiently serializing and
de-serializing an iterable (e.g., list)
Created on 2010-06-19 by Philip Guo
Mostly rewritten 2015-01-16 by Dustin King for Python 3.4
Not backwards compatible.
2.7 version here: https://archive.is/5RZ24
'''
@dmoney
dmoney / funvert.py
Last active January 12, 2019 08:40
# funvert.py
# A hack to enable calling functions as if they were methods
#
# Author: Dustin King ([email protected])
# Grown from this tweet by Zygmunt Zając:
# https://twitter.com/zygmuntzajac/status/685161914117296128
#
# Superseded by: https://github.com/dmoney/funvert
class Funverted:
# bitsnake.rb
# A solution to the Ancient City Ruby 2016 programming challenge:
# http://www.ancientcityruby.com/snake_case/
#
# Dustin King ( [email protected] / @cathodion )
#
# Counts the number of paths through an 10x10 grid of city blocks
# moving only East and South.
EAST_BLOCKS = 10