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 random import randrange | |
#returns your total money after you made a bet. | |
def bet(bet_func, money_pool, coin_func): | |
bet_amount = bet_func(money_pool) | |
return money_pool + bet_amount if coin_func() else money_pool - bet_amount | |
#runs a set of bets and determines whether or not your bets made it to goal(true means it did, false means it hit max_trials before making it to the goal or the money_pool dipped past zero.). | |
def gamble(bet_func, max_trials, goal, money_pool, bet_amount, coin_func): | |
for i in xrange(max_trials): |
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
# Definition for a binary tree node. | |
# class TreeNode(object): | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution(object): | |
def __init__(self): | |
self.result = [] |
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
function recursive_mult(x, y) { | |
if(y === 0 || x === 0) { | |
return 0; | |
} | |
return x + recursive_mult(x, y-1); | |
} | |
console.log(recursive_mult(3,2)); |
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
import time | |
# Given the function: | |
def hello(name): | |
print "hello %s!" % name | |
# Implement logic such that the function cannot be called more than 3 times per second. If that rate is exceeded, raise an exception. |
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 fib(n): | |
if n <= 1: | |
return n | |
mem = [0,1] | |
for i in xrange(2,n+1): | |
mem[(i+1)%2] = sum(mem) | |
return max(mem) | |
def fib(n): | |
if n <= 1: |
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
.section __TEXT,__text,regular,pure_instructions | |
.macosx_version_min 10, 13 | |
.globl _main | |
.p2align 4, 0x90 | |
_main: ## @main | |
.cfi_startproc | |
## BB#0: | |
pushq %rbp | |
Lcfi0: | |
.cfi_def_cfa_offset 16 |
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
#in a matrix of integers find the length of the longest path of increaseing numbers | |
#https://leetcode.com/problems/longest-increasing-path-in-a-matrix/description/ | |
class Solution(object): | |
def __init__(self): | |
self.memo = None | |
def is_bounded(self,i,j,matrix): | |
return not(i < 0 or j < 0 or i >= len(matrix) or j >= len(matrix[0])) | |
#find the length of the longest increasing path from a starting point. |
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
unchangingData: int = 1 | |
def addOne(x: int) -> int: | |
return x + 1 | |
newData: int = addOne(unchangingData) |
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 traverse(x: List[Tuple[int, int]]) -> Optional[List[int]]: | |
if len(x) == 0: | |
return [] | |
not_leaves = {l: True for (l, r) in x if r is not None} | |
leaves = {i: True for j in x for i in j if i not in not_leaves and i is not None} | |
new_x = [(l, None if r in leaves else r) for (l, r) in x if l in not_leaves] | |
recursion = traverse(new_x) | |
return [i for i in leaves] + recursion if len(new_x) < x and recursion is not None else None |
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
# [[A, B]] where A dependes on B -> [B, A] execution order | |
def traverse(x: List[Tuple[int, int]]) -> Optional[List[int]]: | |
if len(x) == 0: | |
return [] | |
# any value that is on the left has a dependency and is not a leaf | |
not_leaves = {l: True for (l, r) in x if r is not None} | |
# every other value that is not in (not_leaves) must be a leaf. | |
leaves = {i: True for j in x for i in j if i not in not_leaves and i is not None} |