Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
# -*- encoding: utf-8 -*-
from __future__ import division
from math import ceil
def triangles(n):
radius = 2 ** int(ceil(n / 2))
skip = 1 + (n % 2)
counts = {}
@robinhouston
robinhouston / index.html
Created February 9, 2015 15:29
Constant flux
<!DOCTYPE html>
<meta charset="utf-8">
<title>Flux</title>
<script src="http://bl.ocks.org/robinhouston/raw/6096562/rAF.js" charset="utf-8"></script>
<script src="streamer.js" charset="utf-8"></script>
<style>
html, body { margin: 0; }
canvas { background-color: #4C4C4C; margin: 8px; }
</style>
@robinhouston
robinhouston / 39dollars75.txt
Created April 27, 2015 11:21
All the ways to make $39.75 from coins of denominations 1¢, 5¢, 10¢, 25¢, and $1
((10, 1), (53, 5), (37, 100))
((5, 5), (74, 25), (21, 100))
((17, 5), (49, 10), (34, 100))
((20, 5), (55, 25), (25, 100))
((35, 5), (30, 10), (35, 100))
((35, 5), (36, 25), (29, 100))
((50, 5), (17, 25), (33, 100))
((53, 5), (11, 10), (36, 100))
((5, 1), (8, 5), (53, 10), (34, 100))
((5, 1), (14, 5), (56, 25), (25, 100))
class lazy(object):
'''A simple lazy evaluation hack, with just enough magic to be
useful for passing as a value to a Django template.
Creates a lazy wrapper around a function call, when used as
lazy(function, argument_1, argument_2, ...)
The resulting object is callable, and calling it (with no arguments) will
evaluate the function on the arguments passed to the constructor.
@robinhouston
robinhouston / gist:772053
Created January 9, 2011 21:42
Make the maze demo from weblog.jamisbuck.org display correctly in IE
diff --git a/jamisbuck-mazes.css b/jamisbuck-mazes.css
index dfbcc74..021bb07 100644
--- a/jamisbuck-mazes.css
+++ b/jamisbuck-mazes.css
@@ -1,6 +1,7 @@
.row .maze {
padding: 0 0 20px 20px;
display: inline-block;
+ float: left;
}
@robinhouston
robinhouston / gist:788007
Created January 20, 2011 14:50
Number of steps taken when switching from Aldous-Broder to Wilson's algorithm at different points
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <bitstring.h>
#define ROWS 10
#define COLS 10
#define REPETITIONS 100000
@robinhouston
robinhouston / gist:848102
Created February 28, 2011 21:45
When is an odd prime the sum of two squares?
Claim:
Let p be an odd prime number. Then the following are equivalent:
1. p is congruent to 1 modulo 4.
2. There is some natural number m such that m^2 + 1 is a multiple of p.
3. p is the sum of two squares.
Proof:
We'll prove (1) => (2) => (3) => (1).
(1) => (2):
# --------------------------------------------------------------------
# An implementation of a "weave" maze generator. Weave mazes are those
# with passages that pass both over and under other passages. The
# technique used in this program was described to me by Robin Houston,
# and works by first decorating the blank grid with the over/under
# crossings, and then using Kruskal's algorithm to fill out the rest
# of the grid. (Kruskal's is very well-suited to this approach, since
# it treats the cells as separate sets and joins them together.)
# --------------------------------------------------------------------
# NOTE: the display routine used in this script requires a terminal
# --------------------------------------------------------------------
# An implementation of a "weave" maze generator. Weave mazes are those
# with passages that pass both over and under other passages. The
# technique used in this program was described to me by Robin Houston,
# and works by first decorating the blank grid with the over/under
# crossings, and then using Kruskal's algorithm to fill out the rest
# of the grid. (Kruskal's is very well-suited to this approach, since
# it treats the cells as separate sets and joins them together.)
# --------------------------------------------------------------------
# NOTE: the display routine used in this script requires a terminal