Skip to content

Instantly share code, notes, and snippets.

@alacret
Created January 28, 2020 01:11
Show Gist options
  • Save alacret/fb40ff3cc0d02cac6739c7476e0cc360 to your computer and use it in GitHub Desktop.
Save alacret/fb40ff3cc0d02cac6739c7476e0cc360 to your computer and use it in GitHub Desktop.
def tetranacci(n=5, output=[0, 0, 0], number=1):
x = n
while n > 0:
output.append(number)
if len(output) >= 4:
number = output[len(output) - 1] + output[len(
output) - 2] + output[len(output) - 3] + output[len(output) -
4]
n -= 1
return output[:x]
SEQ = {
"fib":[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155],
"pad":[ 1, 0, 0, 1, 0, 1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200, 265, 351, 465, 616, 816, 1081, 1432, 1897, 2513, 3329, 4410, 5842, 7739, 10252, 13581, 17991, 23833, 31572, 41824, 55405, 73396, 97229, 128801, 170625 ],
"jac":[0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, 5461, 10923, 21845, 43691, 87381, 174763, 349525, 699051, 1398101, 2796203, 5592405, 11184811, 22369621, 44739243, 89478485, 178956971, 357913941, 715827883, 1431655765, 2863311531, 5726623061],
"pel":[0, 1, 2, 5, 12, 29, 70, 169, 408, 985, 2378, 5741, 13860, 33461, 80782, 195025, 470832, 1136689, 2744210, 6625109, 15994428, 38613965, 93222358, 225058681, 543339720, 1311738121, 3166815962, 7645370045, 18457556052, 44560482149, 107578520350, 259717522849],
"tri":[0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513, 35890, 66012, 121415, 223317, 410744, 755476, 1389537, 2555757, 4700770, 8646064, 15902591, 29249425, 53798080, 98950096, 181997601, 334745777, 615693474, 1132436852],
"tet":[0, 0, 0, 1, 1, 2, 4, 8, 15, 29, 56, 108, 208, 401, 773, 1490, 2872, 5536, 10671, 20569, 39648, 76424, 147312, 283953, 547337, 1055026, 2033628, 3919944, 7555935, 14564533, 28074040, 54114452, 104308960, 201061985, 387559437, 747044834, 1439975216, 2775641472, 5350220959, 10312882481, 19878720128, 38317465040, 73859288608, 142368356257, 274423830033, 528968939938, 1019620414836, 1965381541064, 3788394725871, 7302365621709, 14075762303480, 27131904192124, 52298426843184, 100808458960497, 194314552299285, 374553342295090, 721974780398056, 1391651133952928, 2682493808945359, 5170673065591433],
}
def mixbonacci(pattern, length):
if length == 0 or len(pattern) == 0:
return []
POS = {
"fib":0,
"pad":0,
"jac":0,
"pel":0,
"tri":0,
"tet":0,
}
result = []
for i in range(length):
current_pattern = pattern[i % len(pattern)]
current_pos = POS[current_pattern]
result.append(SEQ[current_pattern][current_pos])
POS[current_pattern] = current_pos + 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment