Skip to content

Instantly share code, notes, and snippets.

View pqcfox's full-sized avatar

kat fox pqcfox

View GitHub Profile
@pqcfox
pqcfox / 9.py
Created January 27, 2015 04:23
An exercise in my Number Theory class.
import math
square_tri = []
def tri(n):
return n*(n+1)/2
k = 1
while len(square_tri) < 4:
val = math.sqrt(tri(k))
@pqcfox
pqcfox / 10.py
Created January 27, 2015 04:23
An exercise in my Number Theory class.
import math
import numpy
a = 2*math.pi
b = 4*math.pi
step = (b - a)/8
for x in numpy.arange(a, b, step):
print("({0}, {1})".format(x, math.cos(x)))
@pqcfox
pqcfox / ppt.py
Last active August 29, 2015 14:14
A simple program that uses a formula for PPT generation.
for s in range(3, 23, 2):
for t in range(1, s, 2):
divides = False
for d in range(2, t + 1):
if s % d == 0 and t % d == 0:
divides = True
break
if divides: continue
c = int((s**2 + t**2)/2)
b = int((s**2 - t**2)/2)
@pqcfox
pqcfox / testwarn.xml
Last active August 29, 2015 14:14
A Google Calendar Gadget designed to warn you about upcoming assessments.
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="TestWarn">
<Require feature="google.calendar-0.5"/>
<Require feature="google.calendar-0.5.read"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
<!DOCTYPE html>
<html>
@pqcfox
pqcfox / unit_ppt.py
Last active August 29, 2015 14:14
A PPT generator which uses the formulae derived in Chapter 3 regarding the unit circle and Pythagorean triples.
def rprime(x, y):
for d in range(2, min(x, y) + 1):
if x % d == 0 and y % d == 0:
return False
return True
for u in range(1, 26):
for v in range(1, u):
a = u**2 - v**2
b = 2*u*v
@pqcfox
pqcfox / cube_square.py
Created January 31, 2015 20:52
A program which finds all (a, b, c) in the positive integers such that a^3 + b^3 = c^2, given that c < 1225.
import math
a_list = []
b_list = []
c_list = []
c_max = 1225
a_max = int((c_max**2)**(1.0/3.0))
for c in range(1, c_max + 1):
@pqcfox
pqcfox / faster.py
Last active August 29, 2015 14:14
A faster version of cube_square which also removes primitives. Just plain fun.
#!/usr/bin/python
import sys
def is_triple(a, b, c):
return a**3 + b**3 == c**2
def primitive(a, b, c):
for d in range(2, min(a, b, c) + 1):
d_squared = d ** 2
@pqcfox
pqcfox / tally_votes.py
Created February 4, 2015 21:42
A tiny vote tallying system for small groups.
import argparse
import collections
import ConfigParser
import gspread
import pyvotecore.irv
import pyvotecore.plurality
import pyvotecore.schulze_method
import pyvotecore.stv
parser = argparse.ArgumentParser(description='Tally votes in a Google Spreadsheet.')
@pqcfox
pqcfox / gcd.py
Created February 4, 2015 22:14
A GCD program which takes in two command line arguments.
import sys
def euclid(a, b):
if a == 0 or b == 0:
return 0
if a % b == 0:
return b
return euclid(b, a % b)
print(euclid(int(sys.argv[1]), int(sys.argv[2])))
@pqcfox
pqcfox / lcm.py
Created February 6, 2015 00:00
Naive LCM finder.
import sys
def lcm(a, b):
bigger = max(a, b)
lcm = bigger
while lcm % a != 0 or lcm % b != 0:
lcm += bigger
return lcm
a, b = [int(k) for k in sys.argv[1:3]]