Skip to content

Instantly share code, notes, and snippets.

@ryannow
ryannow / streakchance.py
Last active November 14, 2023 01:44
A function to calculate the probability of a streak of length k in n tries
import functools
import sys
from argparse import ArgumentParser
@functools.cache
def streak_chance(n, k, p):
# Probability of k successes in k tries is p^k.
if k == n:
return p ** k
@ryannow
ryannow / lottery.py
Last active May 7, 2016 09:00
Script to calculate NBA lottery odds. Includes all pick swaps and transfers relevant to the top 14 picks.
import collections
import csv
chances = {
'PHI': 250,
'LAL': 199,
'BOS': 156,
'PHX': 119,
'MIN': 88,
'NOP': 63,
install.packages("expm")
library(expm)
#If you have 5000 people, what are the chances every birthday is represented at least once?
#method taken from http://mathforum.org/library/drmath/view/56679.html , coded for general solution
#number of days over which people are randomly distributed
n = 365
#Set up an n*n transition matrix.