Skip to content

Instantly share code, notes, and snippets.

@vcwu
vcwu / josephus.py
Created June 19, 2012 20:42
Solving the Josephus problem via recursion
#CS352 Homework 2, Summer '12
#Victoria Wu
#Josephus Problem
#-----------------
#N people are in a circle, with first person (1) holding a hot potato.
#After M passes of the potato, the person holding the potato is out, and the
#game continues with the next person in line picking up the potato.
#Continue until one person remains. Who will be the victor, given (N>0, M>=0)?
@vcwu
vcwu / BraceBalancing.py
Created June 19, 2012 20:43
Balancing braces in user input.
#CS352 - Homework 2, Summer '12
#Victoria Wu
#Write a program to check for balancing symbols.
#Input from user
def balancing(meat):
stk = []
right = ["(","[","{"]
@vcwu
vcwu / gist:2993987
Created June 26, 2012 07:06
Testing Addition
for(int x = 1000; x < 5000; x += 500)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that no terms are like, and nothing
//will simplify.
term t1(i+1, i+2, i+3);
term t2(i+2, i+1, i+1);
@vcwu
vcwu / gist:2994038
Created June 26, 2012 07:17
SimplifyTester
long Poly::simplifyTester()
{
long time = 0;
list<term>* p = this->getTerms();
list<term>* tempList = new list<term>();
if(!p->empty())
@vcwu
vcwu / gist:2994041
Created June 26, 2012 07:18
pOLYtESTER_all like terms
for(int x = 1000; x < 5000; x += 500)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that all terms are alike.
term t1(i+1, 2,2);
term t2(i+2, 2,2);
pol1->addTerm(t1);
@vcwu
vcwu / gist:2994156
Created June 26, 2012 07:39
Modified Simplify Tester for powers of two
for(int x = 1000; x <= 8000; x += x)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that all terms are alike.
term t1(i+1, 2,2);
term t2(i+2, 2,2);
pol1->addTerm(t1);
@vcwu
vcwu / gist:2994175
Created June 26, 2012 07:44
simpify - made upper bound bigger
for(int x = 1000; x <= 32000; x += x)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that all terms are alike.
term t1(i+1, 2,2);
term t2(i+2, 2,2);
pol1->addTerm(t1);
@vcwu
vcwu / gist:2994212
Created June 26, 2012 07:50
addition _updated till 16000
for(int x = 1000; x < 16000; x += x)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that no terms are like, and nothing
//will simplify.
term t1(i+1, i+2, i+3);
term t2(i+2, i+1, i+1);
@vcwu
vcwu / gist:2994298
Created June 26, 2012 08:08
testing Equality
for(int x = 1000; x < 16000; x += x)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that no terms are alike,
//but both polynomials are equal.
term t1(i+1, 2,2+i);
term t2(i+2, 2,2+i);
@vcwu
vcwu / gist:2994374
Created June 26, 2012 08:25
multiply tester
for(int x = 100; x < 800; x += x)
{
Poly* pol1 = new Poly();
Poly* pol2 = new Poly();
for(int i = 0; i < x; i++)
{
//This ensures that no terms are like, and nothing
//will simplify.
term t1(i+1, i+2, i+3);
term t2(i+2, i+1, i+1);