Skip to content

Instantly share code, notes, and snippets.

View starwarsgeek1138's full-sized avatar

Stefanie Acevedo starwarsgeek1138

View GitHub Profile
@starwarsgeek1138
starwarsgeek1138 / loopFinder.py
Last active June 16, 2016 21:18
Python code to find looping subset within a tuple
##Finds looping subsets within a progression of chords, listed as a tuple (lick); outputs loop (as tuple) and # of repetitions within lick
def findLoops(lick):
lickLen = len(lick)
for i in range(1, lickLen - 1):
testLoop = lick[0:i] #find loop to test as subset
loopLen = len(lick[0:i]) #find test loop length
testVal = int(lickLen/loopLen) #find divisor, rounded down
testValRem= lickLen%loopLen #find remainder
if lick == (testLoop * testVal) + testLoop[0:testValRem]: # if lick = a multiple of the loop (including remainder), then loop is valid loop
loop = lick[0:i]
def find_chords(chords, music):
"""Search for chords within music (O(n) time).
:param list chords: chords to look for, in order
:param list music: music to search within
"""
if len(music) < len(chords):
return 0
my_chord_i = -1
occurrences = 0
for my_chord in music: