Last active
June 16, 2016 21:18
-
-
Save starwarsgeek1138/3c42e07dc30ad828f860c3e1d3bcab3b to your computer and use it in GitHub Desktop.
Python code to find looping subset within a tuple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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] | |
repeats = lickLen/float(loopLen) | |
break | |
else: | |
loop = lick | |
repeats = 1 | |
return loop, repeats |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment