Skip to content

Instantly share code, notes, and snippets.

Kieren Davies kierendavies

Block or report user

Report or block kierendavies

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kierendavies
kierendavies / MinHeap.java
Created Apr 23, 2015
An implementation of a minheap
View MinHeap.java
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>();
}
@kierendavies
kierendavies / cube-puzzle-solver.rb
Last active Aug 29, 2015
Solver for the coloured-cubes puzzle that Caleb brought
View cube-puzzle-solver.rb
# 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
View bwt.clj
; 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 / dragon.py
Created May 21, 2013
A dragon curve in pretty colours, produced by a floor turtle.
View dragon.py
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)
@kierendavies
kierendavies / b.py
Created Apr 15, 2013
Google Code Jam 2013 Qualification Round Problem B
View b.py
#!/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 / elianpalindromes.py
Last active Dec 12, 2015
finds words which are mirror-image palindromes in elian script
View elianpalindromes.py
#!/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 / helloworld.py
Created Oct 1, 2012
obfuscated hello world
View helloworld.py
#!/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 / one.py
Created Feb 19, 2012
Embedly Challenge code
View one.py
# 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 / herp
Created Jan 10, 2012
/usr/bin/herp
View herp
#! /usr/bin/python
from sys import argv
argv[0] = argv[0].split("/")[-1]
print " ".join(argv[::-1])
View gist:1447301
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
You can’t perform that action at this time.