Skip to content

Instantly share code, notes, and snippets.

def count_change(amount, coins):
if amount == 0:
return 1
if len(coins) == 0 or amount < 0:
return 0
return count_change(amount - coins[-1], coins) + \
count_change(amount, coins[:-1])
results = {}
import random
def hash_table(m):
""" initial hash table, m empty entries """
return [[] for i in range(m)]
def hash_mod(key, mod, func=hash):
return func(key) % mod
def contained(candidate_key, list_of_items):
class Node():
def __init__(self, val):
self.value = val
self.next = None
def __repr__(self):
return "[" + str(self.value) + "," + str(id(self.next)) + "]"
class LinkedList():
def __init__(self):
def our_for(iterable, what_to_do):
iterator = iter(iterable)
while True:
try:
i = next(iterator)
what_to_do(i)
except StopIteration as e:
return
class A:
@barnash
barnash / digest1.js
Created May 3, 2014 07:44
Code from angular - digest loop presentation
function Scope() {
this.$$watchers = [];
this.$$lastDirtyWatch = null;
}
Scope.prototype.$$areEqual = function(newValue, oldValue, valueEq) {
if (valueEq) {
return _.isEqual(newValue, oldValue);
} else {
return newValue === oldValue ||
@barnash
barnash / bitmap.py
Created May 21, 2014 05:14
Files from the images tirgul
from PIL import Image
from matrix import *
def image2bitmap(path):
''' Given a string 'path' of image file in "real" format (.jpg/.bmp etc.) creates a new file in format .bitmap under the same directory which can then be loaded into class Matrix using Matrix.load() '''
from PIL import Image
image = Image.open(path)
image = image.convert("L")
im = image.load()
w,h = image.size
exports.doTurn = function(pw) {
};
def do_turn(game):
pass