Created
January 6, 2014 21:36
-
-
Save barnash/8290223 to your computer and use it in GitHub Desktop.
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
| 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 = {} | |
| def factorial(n): | |
| result = 1 | |
| for i in range(1, n + 1): | |
| result *= i | |
| return result | |
| def binom2(n, k): | |
| return factorial(n) // (factorial(k) * factorial(n - k)) | |
| def binom(n, k): | |
| if (n, k) in results: | |
| return results[(n, k)] | |
| if k == 0 or k == n: | |
| return 1 | |
| result = binom(n - 1, k - 1) + binom(n - 1, k) | |
| results[(n, k)] = result | |
| return result | |
| def foo(a, b, c, *args): | |
| print(args) | |
| return a + b + c | |
| class Point: | |
| def __init__(self, x = 0, y = 0): | |
| self.x = x | |
| self.y = y | |
| def __add__(self, other): | |
| assert isinstance(other, Point) or isinstance(other, int) | |
| if isinstance(other, Point): | |
| return Point(self.x + other.x, self.y + other.y) | |
| elif isinstance(other, int): | |
| return Point(self.x + other, self.y) | |
| else: | |
| return NotImplemented | |
| def __radd__(self, other): | |
| return self + other |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment