This file contains hidden or 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
m = 2 | |
N = 500 | |
# pre-compute squares | |
D = dict() | |
for n in range(2,2*N): | |
D[n] = n**2 | |
for d in range(3, N): | |
n = m |
This file contains hidden or 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 sys | |
s = int(sys.argv[1]) | |
def next(n): | |
n*= 10 | |
e = (len(str(n))-1) * 2 | |
t = s * 10**e | |
m = n | |
for i in range(10): |
This file contains hidden or 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 sys | |
def first_prime_factor(n,pL): | |
for p in pL: | |
if n % p == 0: | |
return p, n/p | |
return 1,n | |
def get_primes(N): | |
pL = [2,3] |
This file contains hidden or 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 * | |
# requires x != 0 | |
def radial(x,y): | |
r = (x**2 + y**2)**0.5 | |
t = atan(1.0*y/x) | |
return r,t | |
def cartesian(r,t): | |
x = cos(t) * r |
This file contains hidden or 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 sys | |
from operator import itemgetter | |
# greatest common divisor | |
from fractions import gcd | |
# pre-computed triples | |
fh = open('triples.txt') | |
data = fh.read().strip().split('\n') | |
fh.close() |
This file contains hidden or 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 sys | |
from operator import itemgetter | |
# greatest common divisor | |
from fractions import gcd | |
# pre-computed triples | |
fh = open('triples.txt') | |
data = fh.read().strip().split('\n') | |
fh.close() |
This file contains hidden or 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
# greatest common divisor | |
from fractions import gcd | |
n = 100 | |
# pre-compute squares | |
N = 15*n | |
L = [False] | |
L.extend([i**2 for i in range(1,N)]) | |
rL = list() | |
This file contains hidden or 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 next(S,C,T): | |
C2 = (0.5 * (1 + C))**0.5 | |
S2 = 0.5 * S / C2 | |
T2 = S/(1+C) | |
return S2,C2,T2 | |
S = 1/2**0.5 | |
C = S | |
T = S/C | |
n = 4 |
This file contains hidden or 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
''' | |
radius 1 | |
inscribed square | |
a = (2/sqrt(2))^2 = 2 | |
circumscribed square | |
A = 2^2 = 4 | |
''' | |
a = 2 | |
A = 4 | |
s = "%5d %3.10f %3.10f" |
This file contains hidden or 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
p = 4.0/(2**0.5) | |
P=4 | |
def one_round(t): | |
p,P = t | |
P2 = 2*p*P/(p+P) | |
p2 = (p*P2)**0.5 | |
return p2,P2 | |
s = '%3.10f %3.10f' |