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
outcomes = ["AS", "AF", "NS", "NF", "DS", "DF"] | |
# Game played with N-sided dice | |
# Player may reroll R times | |
# Success threshold is max of D dice. | |
def prob(N, R, D): | |
P = {} | |
EV = {} | |
advantage = range( 2 * N // 3 + 1, N+1 ) | |
disadvantage = range( 1, N // 3 + 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
from enumerate import visit_up_to_n | |
import matplotlib.pyplot as plt | |
import math | |
def draw( n ): | |
figures = [] | |
def visitor( collection, cost ): | |
if cost == n: | |
figures.append( collection ) |
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
# Each sequence consists of steps (0,0) (0,1) (1,0) or (1,1) as long as we | |
# don't hit the central diagonal. We are interested in seqeuences that end | |
# at (n-1,n) after 2n-1 steps. | |
def calculate(paths, max_n, min_k, max_k): | |
for k in range( min_k + 1, max_k + 1 ): | |
# TODO: limit y to only those reachable by a sequence of length <= k | |
for y in range( 1, max_n + 1 ): | |
# Skip diagonal and upper-triangulage entries, which are all zero | |
for x in range( 0, y ): | |
p1 = (x,y,k-1) # k'th element is (0,0) |
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
graph G { | |
# 0=red, 1=green, 2=blue, 3=gray | |
graph [nodesep="0.1", ranksep="0.1", pad="0.5"] | |
node [style=filled, fillcolor=white, shape=circle, width=0.4] | |
1 [fillcolor=red] | |
2 [fillcolor=green] | |
3 [fillcolor=gray] | |
4 [fillcolor=blue, fontcolor=white] | |
6 [fillcolor=red] | |
8 [fillcolor=gray] |
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 ortools.sat.python import cp_model | |
import sys | |
# How many squares can be filled in the 10x10 grid such that no five | |
# orthogonally-connected squares are all filled? | |
m = cp_model.CpModel() | |
size = 10 |
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
ALABAMA -- cover DHNOS optionally CEFGIJKPQRTUVWXYZ | |
ALASKA -- cover EHMNO optionally BCDFGIJPQRTUVWXYZ | |
ARIZONA -- cover DEGHLMSW optionally BCFJKPQTUVXY | |
CALIFORNIA -- cover DEGHMSWZ optionally BJKPQTUVXY | |
COLORADO -- cover BEHIKN optionally FGJMPQSTUVWXYZ | |
CONNECTICUT -- cover AGHKMS optionally BDFJLPQRVWXYZ | |
DELAWARE -- cover BHNOS optionally CFGIJKMPQTUVXYZ | |
FLORIDA -- cover BCEHNSW optionally GJKMPQTUVXYZ | |
GEORGIA -- cover HLNSW optionally BCDFJKMPQTUVXYZ | |
HAWAII -- cover LNOST optionally BCDEFGJKMPQRUVXYZ |
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
module Repro (part1) where | |
import qualified Data.Map as Map | |
import Data.List.Split | |
import Data.Either | |
import Data.Maybe | |
import Control.Monad.ST | |
import Data.STRef | |
{-@ |
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 init_4d(n): | |
return [[[[0 for i in range(n)] | |
for j in range(n)] | |
for k in range(n)] | |
for l in range(n)] | |
def recurrence(c,x1,y1,x2,y2): | |
total = 0 | |
# These two cases are always valid; even if the two paths have met at | |
# (x1,y1), then in these cases the previous step cannot be the same, so |
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 cairo | |
import math | |
import itertools | |
def base_position( i, j ): | |
return (i * 60 + 10, j * 50 + 10) | |
def drawGrid( ctx, i, j ): | |
ctx.set_line_width( 1 ) | |
ctx.set_source_rgba( 0.0, 0.0, 0.0, 1.0 ) |
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
module Factorial | |
open FStar.Mul // Give us * for multiplication instead of pairs | |
open FStar.IO | |
open FStar.Printf | |
let rec factorial (n:nat) : nat = | |
if n = 0 then 1 | |
else n * factorial (n-1) |
NewerOlder