Skip to content

Instantly share code, notes, and snippets.

View julius-datajunkie's full-sized avatar

julius-datajunkie julius-datajunkie

View GitHub Profile
@julius-datajunkie
julius-datajunkie / drawdown.py
Created December 2, 2013 18:39
Drawdown Calculation
import numpy as np
import matplotlib.pyplot as plt
def drawdown2(series):
MDD = 0
peak = -99999
length = len(series)
DD = np.zeros(length)
for i in range(length):
if (series[i] > peak): # peak will be the maximum value seen so far (0 to i)
@julius-datajunkie
julius-datajunkie / PrimesGenerator.py
Created October 25, 2013 16:59
This generator generates an infinite sequence of primes, one at a time
# Sieve of Eratosthenes
# Code by David Eppstein, UC Irvine, 28 Feb 2002
# http://code.activestate.com/recipes/117119/
def PrimesGenerator():
"""
Generate an infinite sequence of prime numbers.
"""
# Maps composites to primes witnessing their compositeness.
# This is memory efficient, as the sieve is not "run forward"
import unittest
def LongestZeroSequence(n):
'''
Input: n is a string of a binary sequence
Output: the length of the longest consecutive zero sequence
when encounter 1, stop counting and save the max sequence so far.
output the max sequence
'''
maxSequence = 0
seq = 0
import unittest
def LargestIntDividesEleven(numberOfDigits):
largestInt = 10**(numberOfDigits)-1
return largestInt - (largestInt % 11)
def reverse(number):
'''
This method does not speed things up, but it does provide a rather
interesting way of reversing any integers without converting it to
@julius-datajunkie
julius-datajunkie / Euler Project #3.py
Last active December 26, 2015 03:29
This is very inefficient algorithm to solve the problem. It takes Python more than 5 minutes to solve the problem with the number given
import unittest
from math import sqrt
def isPrime(i):
if (i == 2 or i == 3):
return True
else:
for j in range(3, int(sqrt(i)+1)):
if ( i % j == 0):
return False
return True
@julius-datajunkie
julius-datajunkie / Euler Project #2.py
Last active December 26, 2015 03:19
Will try to implement the second order difference equation formula for this problem.
import unittest
def EvenFibonacciNumbers(limit):
#Find all even fibonacci numbers
fibonacciSeries = FibonacciGenerator(limit)
return sum(i for i in fibonacciSeries if i % 2 == 0)
def FibonacciGenerator(limit):
a = 0
b = 1
@julius-datajunkie
julius-datajunkie / Euler Project #1.py
Last active December 26, 2015 03:19
There must be a faster way than simply iterating through all the numbers
import unittest
def SumMultiplesOfThreeOrFive(number):
return sum(i for i in range(1,number) if (i % 3 == 0 or i % 5 == 0))
#for i in range(1,number):
# if (i % 3 == 0 or i % 5 == 0):
# sum += i
#return sum
class TestSumMultiplesOfThreeOrFive(unittest.TestCase):