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 math | |
import random | |
pdf_memo = {} | |
def pdf(h, n): | |
h = min(h, n-h) | |
if (h, n) not in pdf_memo: | |
pdf_memo[(h, n)] = math.factorial(n)/(math.factorial(h)*math.factorial(n-h))*(0.5**h)*(0.5**(n-h)) |
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 get_last_run(task_name): | |
task = db.scheduled_tasks.find_one({'name': task_name}) | |
if task is None: | |
last_run = time.time() | |
# race condition possible, but this only happens at first run | |
db.scheduled_tasks.update( | |
{ | |
'name': task_name | |
}, |