Instantly share code, notes, and snippets.

# Tom Elliotttelliott99

• Sort options
Created Nov 19, 2018
View complex_power.py
 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
Created Nov 12, 2018
View triples2.py
 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()
Created Nov 12, 2018
View triples2.py
 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()
Created Nov 12, 2018
View triples.py
 # 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()
Created Oct 12, 2018
View pi_by_trig.py
 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
Created Oct 6, 2018
View area_method.py
 ''' 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"
Last active Sep 30, 2018
Archimedes method to compute pi
View pi.py
 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'
Created Jan 15, 2018
View numerical_int.py
 from math import e, pi, sqrt def get_xvalues(a,b,N): dist = 1.0*b - 1.0*a dx = dist/N half = dx/2.0 R = [(a + dx * n + half) for n in range(N)] return R, dx def integrate(a,b,f,N=100):
Created Jan 15, 2018
View gamma2.py
 from matplotlib import pyplot as plt import numpy as np p = 81 q = 219 def f(x): return x**(p-1)*(1-x)**(q-1) X = np.linspace(0,1,1000)
Created Apr 2, 2017
View friends.py
 from random import choice as ch R = range(1,366) # report doubles, triples for a single run def analyze(L): L.sort() rD = dict() i = 0 while i < len(L) - 1: # up to penultimate item v = L[i]
You can’t perform that action at this time.