Skip to content

Instantly share code, notes, and snippets.

View marshareb's full-sized avatar
🏠
Working from home

James Marshall Reber marshareb

🏠
Working from home
View GitHub Profile
@marshareb
marshareb / cantor.py
Created January 25, 2019 17:57
Devils Staircase
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 1), ylim=(0, 1))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
import matplotlib.pyplot as plt
import numpy
# GENERAL FORMAT
# Here, f stands for function, a stands for the beginning of the interval, b stands for the end, and n stands for the number of subdivisions you want to do.
# LEFT RIEMANN PLOT
def plotleftriemannsum(f, a, b, n):
# plot the function
x = numpy.linspace(a, b)
@marshareb
marshareb / count.py
Last active January 12, 2018 13:08
Counts the number of 1's in a binary expansion recursively
def count(n, j = 0):
if n > 1:
if n % 2 == 1:
return count(n//2, j+1)
else:
return count(n//2,j)
elif n == 1:
return j+1
else:
return j
@marshareb
marshareb / randomsequence.py
Created January 11, 2018 15:10
Possible random number generator?
import time
# GET THE DIGITS OF PI
def bbp(start, finish):
def bbp_formula(n):
return (4/(8*n+1)-2/(8*n+4)-1/(8*n+5)-1/(8*n+6))*(1/16)**n
ls = [i for i in range(start, finish+1)]
x= sum(list(map(lambda x: bbp_formula(x), ls)))
return [int(i) for i in str(x) if i.isdigit()]
@marshareb
marshareb / secret_santa.py
Created November 29, 2017 18:59
Emails people secret santa info
import smtplib
import random
from email.message import EmailMessage
# PRIVATE EMAIL INFO
# (This is your email. Note this is not secure, so don't do this on public networks.)
gmail_sender = 'sender@gmail.com'
gmail_passwd = 'password'
def repeating_number(st):
from itertools import islice, chain
def breakup(lis, size):
return filter(None, map(lambda x: list(islice(lis, x, x+size)) if len(list(islice(lis, x, x+size))) == size else
None, [i for i in range(len(lis))]))
def count(lis):
return dict(filter(lambda x: x[1] != 1, map(lambda x: (tuple(x), len(list(filter(lambda x: x,
map(lambda y: y == x, lis))))), lis)))
@marshareb
marshareb / streaming.py
Last active July 4, 2017 22:03
Searches the three major streaming services to see if they have the movie the user wants.
import urllib.request
from bs4 import BeautifulSoup
# Find out if the movies selected are on their websites. Note this is very susceptible to misspellings of the movie.
# Check if it's on hulu by seeing if the availabilityStarts option is on. Movies or shows that are not yet on Hulu
# do not have this feature.
#Change the movieName to be in a nicer format
class Player:
def __init__(self, deck):
self.deck = deck
self.battlefieldl = []
def can_play(self):
return len(self.deck)
def battlefield(self, playvalue):
self.battlefieldl = [self.deck.pop(0) for i in range(min(playvalue, 4))]
@marshareb
marshareb / ramsey.py
Last active June 12, 2017 20:11
Finds the k-th Ramsey number
# TODO: Read the summary of http://ieeexplore.ieee.org/document/5461802/. It talks a bit about how we can construct counterexamples from prior counterexamples. Maybe James needs to prove that all Ramsey graphs Gi exist as subgraphs of graphs G(i+1)?
# TODO: In the checking for all cliques, we can take a large subset instead of scanning the entire thing, narrowing down all possibilities to a smaller subset to search through.
# uses itertools to generate all tuples for k-clique checking
from itertools import combinations
# reduce container items
from functools import reduce
# uses random for the random graph generator
import random
# to time functions
@marshareb
marshareb / correlation.py
Created February 21, 2017 16:19
Finds the covariance, mean, variance, and correlation of two lists (could extend this to more)
import math
import warnings
#find the mean of a list
def mean(list):
x = 0
for i in list:
x+=i
return (x/len(list))