import math
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter as SMF
import numpy as np
import pandas as pd
import seaborn as sns
def findAllSequences(notes) :
end = notes
allSequences = []
if notes == 1 :
allSequences.append([1])
elif notes == 2:
allSequences.append([1, 2])
elif notes == 3:
allSequences.append([1, 2, 3])
else :
initial = []
seq = [1, 2]
for note in range(3, end+1):
seq.append(note)
initial.append(seq.copy())
for i in initial :
someSequences = reversions(i, i, end)
allSequences += someSequences
final = []
for seq in allSequences :
if seq not in final:
final.append(seq)
return(final)
def reversions(seq, recent, end) :
someSequences = []
#Beginning of recent.
r_1 = recent[0]
#End of recent.
r_end = recent[-1]
#Last note can only be played once.
if r_end == end:
someSequences.append(seq)
else:
#Beginning of reversion has to be at least one greater than beginning of recent,
#and has to be the lesser of the maximum of the end or two less than end.
x = max(seq)
for b in range(r_1 + 1, x+1) :
reversion = []
rev_end = r_end
#The numbers in the reversion can be any sequence from defined beginning to the last note.
for n in range(b, end + 1) :
#At no point can they play the same note twice in a row.
if n == rev_end :
next
else:
#Append the next note to the current reversion.
reversion.append(n)
rev_end = n
if len(reversion) >= 2 :
#Sequence that was input before reversions began.
temp = seq.copy()
#Append the reversion to the sequence.
temp += reversion
#Check for the end, or append more reversions.
someSequences += reversions(temp, reversion, end)
return(someSequences)
seq = []
for i in range(1, 11) :
seq.append(len(findAllSequences(i)))
df = pd.DataFrame(data = seq,
columns = ["Sequences"],
index = range(1,11))
df
Sequences | |
---|---|
1 | 1 |
2 | 1 |
3 | 1 |
4 | 2 |
5 | 6 |
6 | 25 |
7 | 131 |
8 | 817 |
9 | 5888 |
10 | 48129 |
def findAllSequences2(notes) :
end = notes
allSequences = []
if notes == 1 :
allSequences.append([1])
elif notes == 2:
allSequences.append([1, 2])
elif notes == 3:
allSequences.append([1, 2, 3])
else :
initial = []
seq = [1, 2]
for note in range(3, end+1):
seq.append(note)
initial.append(seq.copy())
for i in initial :
someSequences = reversions(i, i, end)
allSequences += someSequences
return(allSequences)
len(findAllSequences2(8))
1939