This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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 | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer