Skip to content

Instantly share code, notes, and snippets.

; Burrows-Wheeler Transform (and inverse)
; http://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform
(def string-start \u0098)
(defn bwt [s]
(map last
(sort-by vec
(take (inc (count s))
(iterate #(concat (rest %)
@kierendavies
kierendavies / cube-puzzle-solver.rb
Last active August 29, 2015 14:19
Solver for the coloured-cubes puzzle that Caleb brought
# This program solves a puzzle I encountered recently.
# The puzzle consists of four cubes, each face of which has one of four colours.
# The objective is to arrange them in a column so that, looking down each side
# of the column, the four visible colours are all different.
require 'pp'
require 'set'
# A cube with colours attributed to its faces.
class Cube
@kierendavies
kierendavies / MinHeap.java
Created April 23, 2015 15:24
An implementation of a minheap
import java.util.ArrayList;
import java.util.Random;
public class MinHeap<T extends Comparable<T>> {
private ArrayList<T> values;
public MinHeap() {
values = new ArrayList<T>();
}
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
sudo tar jxvf wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2 -C /opt
sudo rm /usr/bin/wkhtmltopdf
sudo ln -s /opt/wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
rm wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2
@kierendavies
kierendavies / herp
Created January 10, 2012 09:33
/usr/bin/herp
#! /usr/bin/python
from sys import argv
argv[0] = argv[0].split("/")[-1]
print " ".join(argv[::-1])
@kierendavies
kierendavies / one.py
Created February 19, 2012 22:01
Embedly Challenge code
# my first solution (lost) in the interactive interpreter used DP, but this
# is fast enough
fac = lambda x: reduce(lambda a, b: a * b, range(1, x + 1))
R = lambda x: sum(int(c) for c in str(fac(x)))
x = 1
while R(x) != 8001:
x += 1
print(x)
@kierendavies
kierendavies / helloworld.py
Created October 1, 2012 03:54
obfuscated hello world
#!/usr/bin/python3
# does not work with python 2.x
print("".join(map(lambda x: chr((lambda p, x: int(sum(map(lambda i: p[i]*x**(11-i), range(12))) + 0.001))([__import__("struct").unpack('>d', bytes([int(s[8*i:8*i+8], 2) for i in range(8)]))[0] for s in ["1011111101010000111010100110011000001101001100000110010001011111", "0011111110110000000101110100001011100000001010111100100101110011", "1011111111111010101001111000010001111000000111111001101001000100", "0100000000111001001101110000110101000110000001010100001100011000", "1100000001101110000010000010100110101001111010000000111011101101", "0100000010010111011001010111000101110010000010000101010111011100", "1100000010110111111110111100001101011100011011101001111111101100", "0100000011001111101011010010010111011011001011001000001110000011", "1100000011011001100001011001001010011100110001010011010100111001", "0100000011010110010101010110010000110001111011111110011001000111", "1100000010111111100000011000011000100110010110100001000110110110", "0100000001010001111
@kierendavies
kierendavies / elianpalindromes.py
Last active December 12, 2015 07:39
finds words which are mirror-image palindromes in elian script
#!/usr/bin/python3
# find words which are mirror-image palindromes in elian script
with open("/usr/share/dict/words", encoding="utf-8", errors="ignore") as fin:
words = [word.strip().lower() for word in fin.readlines()]
sub = {'i': 'c', 'h': 'b', 'k': 'q', 'j': 'p', 'm': 'm', 'l': 'r', 'o': 'o', 'n': 'n', 'a': 'g', 'c': 'i', 'b': 'h', 'e': 'e', 'd': 'd', 'g': 'a', 'f': 'f', 'y': 's', 'x': 'x', 'z': 't', 'q': 'k', 'p': 'j', 's': 'y', 'r': 'l', 't': 'z', 'w': 'w', 'v': 'v'}
for word in words:
@kierendavies
kierendavies / b.py
Created April 15, 2013 21:24
Google Code Jam 2013 Qualification Round Problem B
#!/usr/bin/python3
from itertools import product
T = int(input())
for t in range(T):
N, M = list(map(int, input().split()))
grid = [list(map(int, input().split())) for n in range(N)]
rowmax = list(map(max, grid))
@kierendavies
kierendavies / dragon.py
Created May 21, 2013 16:15
A dragon curve in pretty colours, produced by a floor turtle.
import turtle as t
from math import sin, pi, log
f = 1
l, r = True, False
t.reset()
t.speed(0)
t.hideturtle()
t.bgcolor(0, 0, 0)