Skip to content

Instantly share code, notes, and snippets.

View wmmnola's full-sized avatar

Wade Marshall wmmnola

  • Birmingham, AL
View GitHub Profile
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
@wmmnola
wmmnola / collatz.py
Created October 29, 2019 21:45
Implementation of the sequence which is the subject of the collatz conjecture
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
@wmmnola
wmmnola / erasto.py
Last active June 15, 2020 16:26
A function which generates finds the primes up to a given n
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
@wmmnola
wmmnola / fizzbuzz.s
Created October 26, 2019 23:23
AT&T Assembly implementation of Fizzbuzz
.fizz : .string "Fizz"
.buzz : .string "Buzz"
.endline : .string ":%d \n"
.global main
.newline:
push %rdi
push %rsi
mov $.endline, %rdi
mov %r8, %rsi
@wmmnola
wmmnola / fizzbuzz.py
Created October 26, 2019 22:04
A very compact and neat fizzbuzz solution
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)
@wmmnola
wmmnola / cheb_distortion.py
Last active April 12, 2021 13:58
Chebyshev Distortion
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))
@wmmnola
wmmnola / dist.py
Last active June 21, 2019 16:51
Modeling distortion as a transfer function
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
@wmmnola
wmmnola / slowsqrt.c
Created December 25, 2017 18:48
Continued Fraction implementation of sqrt(n) for fun
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){