Skip to content

Instantly share code, notes, and snippets.

@pAulseperformance
Created October 17, 2019 16:22
Show Gist options
  • Save pAulseperformance/c2703de3ae29b4c33189645a5263868e to your computer and use it in GitHub Desktop.
Save pAulseperformance/c2703de3ae29b4c33189645a5263868e to your computer and use it in GitHub Desktop.
String Permutations For Pinescript Matrix
# https://www.mathsisfun.com/combinatorics/combinations-permutations-calculator.html
b1 = 'b1'
b2= 'b2'
b3='b3'
b4='b4'
b5='b5'
b6='b6'
a1 = [b1],[b2],[b3],[b4],[b5],[b6]
a2 = [b1,b2],[b1,b3],[b1,b4],[b1,b5],[b1,b6],[b2,b3],[b2,b4],[b2,b5],[b2,b6],[b3,b4],[b3,b5],[b3,b6],[b4,b5],[b4,b6],[b5,b6]
a3 = [b1,b2,b3],[b1,b2,b4],[b1,b2,b5],[b1,b2,b6],[b1,b3,b4],[b1,b3,b5],[b1,b3,b6],[b1,b4,b5],[b1,b4,b6],[b1,b5,b6],[b2,b3,b4],[b2,b3,b5],[b2,b3,b6],[b2,b4,b5],[b2,b4,b6],[b2,b5,b6],[b3,b4,b5],[b3,b4,b6],[b3,b5,b6],[b4,b5,b6]
a4 = [b1,b2,b3,b4],[b1,b2,b3,b5],[b1,b2,b3,b6],[b1,b2,b4,b5],[b1,b2,b4,b6],[b1,b2,b5,b6],[b1,b3,b4,b5],[b1,b3,b4,b6],[b1,b3,b5,b6],[b1,b4,b5,b6],[b2,b3,b4,b5],[b2,b3,b4,b6],[b2,b3,b5,b6],[b2,b4,b5,b6],[b3,b4,b5,b6]
a5 = [b1,b2,b3,b4,b5],[b1,b2,b3,b4,b6],[b1,b2,b3,b5,b6],[b1,b2,b4,b5,b6],[b1,b3,b4,b5,b6],[b2,b3,b4,b5,b6]
a6 = [b1,b2,b3,b4,b5,b6]
matrix = [a1,a2,a3,a4,a5]
count = 0
ret = 'ret = '
for array in matrix:
for a in array:
line = f'r{count} = '
count += 1
inverse = []
for i in a:
inverse.append(i.split('b')[1])
a1 = '' if str(1) in inverse else 'not '
a2 = '' if str(2) in inverse else 'not '
a3 = '' if str(3) in inverse else 'not '
a4 = '' if str(4) in inverse else 'not '
a5 = '' if str(5) in inverse else 'not '
a6 = '' if str(6) in inverse else 'not '
line += '{0}a1 and {1}a2 and {2}a3 and {3}a4 and {4}a5 and {5}a6 ? '.format(a1,a2,a3,a4,a5,a6)
for i in a:
if i == a[-1]:
line += i + " : false"
else:
line += i + " and "
ret += f'r{count} or '
print(line)
print(f'r{count} = a1 and a2 and a3 and a4 and a5 and a6 ? b1 and b2 and b3 and b4 and b5 and b6 : false')
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment