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 random import gauss | |
from random import uniform | |
def dist2(party, voter): | |
progdist = (party.prog - voter.prog)**2 | |
econdist = (party.econ - voter.econ)**2 | |
mildist = (party.mil - voter.mil)**2 | |
return progdist + econdist + mildist |
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 collatz(n): | |
c = n/2 if n % 2==0 else (3*n+1)/2 | |
return int(c) | |
def seq(n, func=collatz): | |
lst = [] | |
while(n != 1): | |
lst.append(n) | |
n = func(n) | |
return lst |
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 erasto(n): | |
primes = [True] * n | |
sq = int(math.floor(math.sqrt(n))) | |
for i in range(2,sq): | |
j = i**2 | |
while j < n: | |
primes[j] = False | |
j += i | |
return primes |
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
.fizz : .string "Fizz" | |
.buzz : .string "Buzz" | |
.endline : .string ":%d \n" | |
.global main | |
.newline: | |
push %rdi | |
push %rsi | |
mov $.endline, %rdi | |
mov %r8, %rsi |
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 fizzbuzz(n): | |
for i in range(0, n): | |
s = "%d : " % i | |
s += "fizz" if i % 3 == 0 else "" | |
s += "buzz" if i % 5 == 0 else "" | |
print(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
import numpy as np | |
def cheb(n,x): | |
if(n == 1): return x | |
if(n == 0): return 1 | |
else: return 2*x*cheb(n-1, x) - cheb(n-2, x) | |
def add_cheb_distortion(signal, n, ampl = lambda x: 1): | |
squash = lambda x,k,L,A: (L-A)/(1+np.exp(k*x)) |
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 numpy as np | |
import scipy.signal as sig | |
def dist(s, H, G): | |
f = np.linspace(0, 1000, len(s)) | |
H_seq = [H(f),H(f)] | |
inv_fft = np.real(fft.ifft(H_seq)) | |
final = sig.convolve(s, inv_fft, method='auto') | |
return G * final |
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
float slowsqrt(float n); | |
float nestedSqrt(float n, float level); | |
float slowsqrt(float n){ | |
float s = 1 + ((n-1)/nestedSqrt(n,0)); | |
return s; | |
} | |
float nestedSqrt(float n, float level){ | |
if(level < 30){ |