Skip to content

Instantly share code, notes, and snippets.

View robert-king's full-sized avatar

Robert King robert-king

View GitHub Profile
@robert-king
robert-king / B.py
Created April 9, 2013 04:17
my wrapper for the google code jam command line tool. Feedback welcome.
from gcj_context import in_out, test_in_out
def solve_test_case(data):
stuff = next(data)
return "my_answer_from_stuff"
def main():
#with test_in_out() as (in_file, out_file):
@robert-king
robert-king / fenwick_tree.py
Created May 28, 2013 03:51
Python Binary Index Tree (Fenwick tree) with range updates.
__author__ = 'robert'
"""
Implementation inspired by Petr Mitrichev's blog post http://petr-mitrichev.blogspot.co.nz/2013/05/fenwick-tree-range-updates.html
and
Yoshiya Miyata's Quora answer http://qr.ae/pHhNN
"""
class Bit:
def __init__(self, n):
from bisect import bisect_left
__author__ = 'Robert'
"""
Fizz Buzz and Zing on multiples of two, three and five.
Find the 1000th number that doesn't have a Fizz, Buzz or Zing.
"""
@robert-king
robert-king / treasure.py
Created April 21, 2014 11:26
CodeJam Treasure solution
__author__ = "google.com/+robertking"
"""
One of my favorite code jam problems.
solution to the Treasure problem from google code jam 2013:
https://code.google.com/codejam/contest/dashboard?c=2270488#s=p3
"""
from sys import stdin
from collections import Counter, defaultdict
//google.com/+robertking
//One of my favorite code jam problems.
//solution to the Treasure problem from google code jam 2013:
//https://code.google.com/codejam/contest/dashboard?c=2270488#s=p3
//also wrote a solution in python: https://gist.github.com/robert-king/11139975
package main
import (
@robert-king
robert-king / tsort.go
Created October 18, 2014 01:57
Codechef TSORT (Turbo Sort)
package main
import (
"os"
)
//google.com/+robertking
//fastest go solutions:
//http://www.codechef.com/status/TSORT?sort_by=Time&sorting_order=asc&language=114&status=15&handle=&Submit=GO
//(It's 3.8x slower than C & C++. Slightly faster than Java.)
@robert-king
robert-king / trie.go
Last active August 29, 2015 14:21
golang implementation of Trie datastructure with Load & Save to persist to google appengine datastore
package trie
import (
"appengine/datastore"
"appengine"
"encoding/gob"
"bytes"
)
//@robertkingNZ
// in this example we don't need Math.floor, we just check i < j
function isPalindrome(phrase){
alpha = [];
for (var char of phrase.toLowerCase()) {
if ('a' <= char && 'z' >= char) {
alpha.push(char);
}
}
phrase = alpha.join('');
@robert-king
robert-king / shutdown_servers.py
Created April 20, 2019 12:26
shutdown servers
# given matrix of servers, servers connect to servers in their row or column. 'C' denotes a server computer.
# shutdown the servers in an order such that shutdown servers pass their data on to nearby servers, such that
# the minimum number of servers need to stay on.
# author: @robertkingnz
def make():
M = []
rows = 10
cols = 20