This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From hacker news | |
| # http://apps.ycombinator.com/item?id=2267312 | |
| def subset_summing_to_zero(activities): | |
| subsets = {0: []} | |
| for (activity, cost) in activities.iteritems(): | |
| old_subsets = subsets | |
| subsets = {} | |
| for (prev_sum, subset) in old_subsets.iteritems(): | |
| subsets[prev_sum] = subset | |
| new_sum = prev_sum + cost |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # Response to challenge at http://beust.com/weblog/2011/10/30/a-new-coding-challenge/ | |
| import sys | |
| from itertools import combinations, chain | |
| N = 40 | |
| def powerset(iterable): | |
| "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" | |
| s = list(iterable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // see http://stackoverflow.com/questions/8697095/how-to-read-a-png-file-in-gray-scale-using-the-go-programming-language | |
| // Many thanks to Evan Shaw http://stackoverflow.com/users/510/evan-shaw | |
| package main | |
| import ( | |
| "image" | |
| "image/png" // register the PNG format with the image package | |
| "os" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| # Filters a mysql dump file to migrate from 4.0.23 to 5.x | |
| use strict; | |
| use warnings; | |
| while (<>) { | |
| s/TYPE=MyISAM/ENGINE=MyISAM/g; | |
| s/timestamp\(14\)/timestamp/g; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # solution to http://beust.com/weblog/2012/09/02/coding-challenge-a-sliding-window-map/ | |
| import heapq | |
| import time | |
| class SlidingWindowMap(object): | |
| def __init__(self,api_keys,max_count,period_minutes): | |
| self.period = period_minutes * 60 | |
| self.pq = [] | |
| for api_key in api_keys: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Calculate the expected percentage of pairs of socks recovered | |
| # after randomly washing a sample | |
| from random import shuffle, sample | |
| from collections import defaultdict | |
| from time import clock | |
| PAIRS = 20.0 | |
| EXPERIMENTS = 1000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use 5.010; | |
| use strict; | |
| use warnings; | |
| use Flickr::Upload; | |
| use File::Spec; | |
| use File::Find; | |
| use Config::Simple; | |
| use Path::Class; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use 5.010; | |
| use strict; | |
| use warnings; | |
| use File::Path qw (remove_tree); | |
| while ( my $path = <> ) { | |
| chomp $path; | |
| my $errors; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use 5.010; | |
| use strict; | |
| use warnings; | |
| use HTTP::Tiny; | |
| my $ratings = 'http://jenkins-ci.org/rate/result.php'; | |
| my $response = HTTP::Tiny->new->get($ratings); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # Does this work? | |
| # http://blog.jgc.org/2013/04/the-minimum-coin-problem-with-prize.html | |
| coins = [200,50,50,100,100,20,20,20,10,5,5,2,2,1,1] | |
| coins.sort() | |
| coins.reverse() | |
| paper = 170 |