Instantly share code, notes, and snippets.

# M Hickfordhickford

• Sort options
Created May 25, 2013
View essay.txt
Last active Dec 17, 2015
Solve coin problem from http://blog.jgc.org/2013/04/the-minimum-coin-problem-with-prize.html
View coins.py
 #!python # -*- coding: utf-8 -*- # http://blog.jgc.org/2013/04/the-minimum-coin-problem-with-prize.html # I have in my pocket the following British coins: one £2, two £1, two 50p, three 20p, one 10p, two 5p, two 2p and two 1p. I wish to buy a copy of today's paper at a cost of £1.70. # What is the maximum number of coins I can use to pay for the paper? With the restriction that I pay in a reasonable manner (e.g. I could give exactly £1.70 or an amount greater than that but without giving extraneous coins: e.g. giving the seller all the coins would not be acceptable, but giving him one £1 an two 50ps and expecting 30p in change is OK). The reasonable manner is simply: if I give the seller a set of coins he should not be able to return any to me without the sum of the remaining coins dropping below £1.70. from collections import Counter, OrderedDict def solve_exact(coins, P, f=len):
Created May 7, 2013
Attempted solution to Google Code Jam's Osmos problem. Turned out to be incorrect. https://code.google.com/codejam/contest/2434486/dashboard
View osmos.py
 #!python # https://code.google.com/codejam/contest/2434486/dashboard # Armin is playing Osmos, a physics-based puzzle game developed by Hemisphere Games. In this game, he plays a "mote", moving around and absorbing smaller motes. # lemma if we delete a mote size x, we should delete all motes greater than size x import fileinput f = fileinput.input() T = int(f.readline())
Created Mar 11, 2013
Ordered dictionary class for C# and .NET (an omission from the standard library). A dictionary that remembers the order that keys were first inserted. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end. See http://stackoverflow.com/questions…
View OrderedDictionary.cs
 using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; /// /// A dictionary that remembers the order that keys were first inserted. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end. /// /// The type of keys
Created May 28, 2012
Reactive Extension's Where method reimplemented
View reactive-where.cs
 public static class ObservableExtensions { public static IObservable Where (this IObservable source, Func predicate) { if (source == null) { throw new ArgumentNullException("source"); } if (predicate == null) {
Created May 24, 2012
C# foreach loop with different action for final item
View foreach-final-item.cs
 public static class EnumerableExtensions { /// /// Perform an action on each element of an IEnumerable, optionally specifying a different action for the final item. /// public static void ForEach(this IEnumerable source, Action action, Action finalAction=null) { if (source == null) { throw new ArgumentNullException("source");
Created Apr 25, 2012
keyboard churn
View keyboard-churn.coffee
 #!/usr/bin/env coffee process.stdin.resume() require('tty').setRawMode(true) history = {} plans = {} spew = () -> console.log(new Date) setInterval spew, 1000
Created Apr 1, 2012
GroupAdjacentBy method for .NET in C#