- is
- this
- markdown
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 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 |
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
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 |
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 fractions import gcd | |
M = 19*41*47*61 | |
totient = 18*40*46*60 | |
def p(n): | |
return (n*n*n*n + n*n + n + 1) % M | |
# compute inverse of a mod M | |
# or None if no inverse exists |
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 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 |
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
# Determine how many ways the US election could end in electoral tie. | |
# Respsonse to https://twitter.com/daveinstpaul/status/792788962230226944 | |
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, | |
11,29,3,38,16,5,6,4,6,3,4,4,13,20,14,12,11,5,5,6,29,10,6,15,3] | |
@lru_cache(maxsize=10000) | |
def count_ties(subtotal, votes): |
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 random | |
N = 2018 | |
trials = 10000 | |
def connect(wires): | |
loops = 0 | |
while wires > 1: | |
v, w = random.randrange(wires), random.randrange(wires) | |
if v == w: |
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
PAGE 58,132 | |
;---------------------------------------------------------------------------- | |
; Hier sind der neu SETUP komputerprogramm. | |
;---------------------------------------------------------------------------- | |
.386P | |
FALSE EQU 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
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)) | |
@lru_cache(maxsize=512) | |
def p(S): # S is a frozenset so it can be cached | |
if len(S) == 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
#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; |
OlderNewer