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 / Find_auto.py
Last active February 16, 2017 01:23
Finds the automorphism group up to isomorphism for the cyclic group of size n. Also note that this technically finds all of the generators of the finite cyclic group of size n, since Aut(Zn) = U(n)
import warnings
try:
import euclideanalgorithm as ea
except:
warnings.warn('make sure to import the euclidean algorithm program')
#From Gallian
#Finds the size of the automorphism group of the cyclic integer group of size n
def find_automorphism(n):
@marshareb
marshareb / tictactoe.cpp
Last active February 16, 2017 01:09
A basic tic tac toe game.
//Tic tac toe game in c++
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
@marshareb
marshareb / blackjack.cpp
Created December 31, 2016 02:12
Using OOP to make a basic blackjack program. Some imporvements might be to actually account for a real deck of cards. I also don't know the rules of blackjack super well, so this is probably flawed in some way.
// Blackjack
#include <iostream>
#include <cstdlib>
using namespace std;
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
@marshareb
marshareb / Homeworkupdater.py
Last active November 29, 2017 19:02
Checks a website to see if it has been updated, and emails you if it has.
import urllib2
import time
import text
import smtplib
#This is configured for gmail, specifically.
def sendEmail(username, password, msg, toaddrs):
fromaddr = username
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
@marshareb
marshareb / pagerank.py
Last active February 8, 2017 00:12
Does google's pagerank algorithm on a directed graph. Requires networkx for the graphs.
try:
import networkx as nx
except ImportError:
raise ImportError('Requires networkx')
def pageranker(g, damp, iterations):
#Does this for a set amount of iterations.
#In the future, may add convergence conditions.
#Not optimal for large graphs. Should probably store the connected_to list somewhere instead of calling it each time.
dict_of_ranks = {}
@marshareb
marshareb / euclideanalgorithm.py
Last active February 14, 2017 00:57
Algorithms to find gcd and to reduce fractions
import warnings
def warn(m,n):
#If m,n are not integers, or are not less than 0, return a warning
if type(m) != int or type(n) != int or m < 0 or n < 0:
warnings.warn("Input was not a strictly positive integer")
def euclidean_division(m, n):
#The Euclidean division algorithm takes two inputs, m and n in this case, and returns two values which represent
#q and r such that, if m > n, m = qn + r, where 0 <= r < n.
@marshareb
marshareb / polynomialdivision.py
Last active February 14, 2017 00:58
Algorithms to multiply, divide, add, and subtract polynomials. Also some various functions to go with it. Note that we have that a polynomial is a list [t1, t2, ...] where we have t1 + xt2 + x^2 t3 + ...
import warnings
#this is just for notational simplicity
def degree(f):
try:
return len(f)-1
except:
return 0
# -----------------------------------------------------------------------------------------------------------------------
#also for notational simplicity
@marshareb
marshareb / truthtablechecker.py
Last active February 8, 2017 23:37
Generates truth tables for boolean expressions.
#Generates the truth table for n variables
def truthtable (n):
if n < 1:
return [[]]
subtable = truthtable(n-1)
return [ row + [v] for row in subtable for v in [0,1] ]
#Prints the first truth table in a nice manner.
def print_truth_table(lis, num_of_variables):
stri = "| "
@marshareb
marshareb / linear_regression.py
Created February 16, 2017 00:44
Preforms simple linear regression in python
import warnings
#-----------------------------------------------------------------------------------------------------------------------
#power function
#python has one built in but the point of this program is to do unecessary things for practice
def power(x, pow):
if type(pow) != int and pow > 0:
warnings.warn("pow needs to be an integer value greater than 0")
if pow == 0:
return 1
for i in range(pow-1):
@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))