Skip to content

Instantly share code, notes, and snippets.

iconjack /
Created Feb 6, 2020
Compute expected number of turns in Snakes & Ladders
import numpy as np
# Compute expected number of turns to complete a snakes & ladders
# track of length n, given a set of portals (snakes and ladders),
# which are both represented as lists of pairs (start, end).
# It's ok to pass lists of [start, end] instead of pairs (start, end).
def E(n, portals):
portal_map = {k: k for k in range(n)} # identity map
View pop.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
typedef uint8_t byte;
typedef uint32_t quart;
typedef uint64_t pottle;
iconjack /
Created Dec 19, 2018
Compute probability of winning High Rollers dice game.
from fractions import Fraction
from functools import lru_cache
from itertools import *
def powerset(S):
return chain.from_iterable(combinations(S, r) for r in range(len(S)+1))
def p(S): # S is a frozenset so it can be cached
if len(S) == 0:
PAGE 58,132
; Hier sind der neu SETUP komputerprogramm.
import random
N = 2018
trials = 10000
def connect(wires):
loops = 0
while wires > 1:
v, w = random.randrange(wires), random.randrange(wires)
if v == w:
iconjack /
Created Nov 2, 2016
Determine how many ways the US election could end in electoral tie
# Determine how many ways the US election could end in electoral tie.
# Respsonse to
from functools import lru_cache
votes = [9,8,3,3,8,18,11,4,7,6,10,7,55,11,20,9,16,4,7,10,9,3,6,3,3,10,
def count_ties(subtotal, votes):
iconjack /
Created Jan 1, 2016
shows what happens when you mix large and small sample sizes
import matplotlib.pyplot as plt
from pylab import savefig
import numpy as np
from numpy.random import rand, randint
def flipsome(n):
flip = lambda: randint(0,2)
return sum(flip() for _ in range(n)) / float(n)
interval = 1000
iconjack / kenled
Created Jul 31, 2014
Solutions to Ken's LED Puzzle
View kenled
digits = [
# B C D A B C A B C
# E F F F F
# G H H H H
# I L L J K J K
# M N N M N
# O P P O P
# R S T Q R S T Q R S
View nytimes
from math import sqrt
from itertools import permutations
def squarable(sides):
area = sum(map(lambda (a,b): a*b, sides))
S = sqrt(area)
if S == int(S):
# check Ken's conditions