This file contains 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
class Trie(): | |
def __init__(self, words=()): | |
self.root = {} | |
for word in words: | |
self.add(word) | |
def add(self, word): | |
current = self.root | |
for letter in word: |
This file contains 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 collections import deque | |
from itertools import combinations | |
try: | |
from itertools import ifilter | |
except ImportError: | |
ifilter = filter # python 3 | |
import timeit | |
def abarnert(n, r): | |
def good(combo): |
This file contains 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
package | |
{ | |
import flash.display.Graphics; | |
import net.flashpunk.Entity; | |
import net.flashpunk.FP; | |
import net.flashpunk.Graphic; | |
import net.flashpunk.graphics.Image; | |
import net.flashpunk.graphics.Text; | |
import net.flashpunk.Tween; | |
import net.flashpunk.tweens.misc.VarTween; |
This file contains 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
def binomial_coefficient(n, k): | |
"""Returns the binomial coefficient, "n choose k".""" | |
if k > n-k: # if k is greater than n/2, swap it for n-k which will be | |
k = n-k | |
result = 1; | |
for i in range(k): # loop from 0 to k-1 | |
result *= (n-i) / (i+1) # multiply in one term of the result | |
return result |