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 / hashcode 2020 online qualification.py
Created February 20, 2020 21:40
google hashcode 2020 online qualification
# incomplete code by @robertkingNZ of team @perplexico_
import sys
import collections
Library = collections.namedtuple('Library', ['id', 'signup', 'per_day', 'bookids'])
def get_problem_from_file(f):
lines = (line for line in f.read().splitlines())
rows = (list(map(int, line.split())) for line in lines)
@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
// 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 / 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
@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.)
//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 / 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
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 / 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):