Skip to content

Instantly share code, notes, and snippets.

@lastforkbender
Last active May 31, 2024 02:08
Show Gist options
  • Select an option

  • Save lastforkbender/acce69805353ffa02b7dfffefe4fb3d3 to your computer and use it in GitHub Desktop.

Select an option

Save lastforkbender/acce69805353ffa02b7dfffefe4fb3d3 to your computer and use it in GitHub Desktop.
Collatz seq palindrome merge or break algirithm
# COLLATZ SEQUENCES, PALINDROME MERGE OR BREAK ALGORITHM MODULE, ICRS.py
# https://github.com/lastforkbender/staqtapp
from collections import deque
import math
import random
class ICRS():
__slots__ = ()
def __init__(self):
pass
class TT777_SPICE(ICRS):
__slots__ = ('_sCltzSeq','_sSeqSet','_sSeqIdx','_sPlndrmSeq','_sLstA','_sIntA','_sIntB','_rLstA','_rLstB','_rLstC','_rStrA','_rStrB','_rStrC','_rStrD','_rIntA','_rIntB','_rIntC','_rIntD','_rIntE','_rIntF','_rIntG','_rBoolA')
def __init__(self):
self._sSeqIdx = 0
#<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>
def collatz(self):
self._rIntA = self._sSeqSet[self._sSeqIdx]
self._sSeqIdx+=1
print(f'___|> New start sequence number: {self._rIntA}')
self._sCltzSeq = deque()
self._sCltzSeq.append(self._rIntA)
while self._rIntA != 1:
if self._rIntA % 2 == 0: self._rIntA = self._rIntA // 2
else: self._rIntA = 3 * self._rIntA + 1
self._sCltzSeq.append(self._rIntA)
print(f'___|> Finished collatz sequence: {self._sCltzSeq}')
print('\n')
#<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>
def findSpice(self):
# slots attrs in strict refrence: (_sLstA, _sIntA, _sIntB)
self._sIntB = len(self._sCltzSeq)
self._sPlndrmSeq = deque()
for self._sIntA in range(self._sIntB):
self._rStrB = str(self._sCltzSeq[self._sIntA])
if len(self._rStrB) > 1 and self._rStrB == self._rStrB[::-1]:
self._sPlndrmSeq.append(self._sCltzSeq[self._sIntA])
print(f'___|> Spice number/palindrome ({self._rStrB}) found in collatz sequence')
print(f'_________|.> total spice ({len(self._sPlndrmSeq)}) found so far')
print('\n')
else:
if self._rStrB.find('9') > -1:
print(f'___|> Base10 loop-shifter "smiling 9" found in sequence number')
print(f'_________|.> starting menorah based group calculations')
self._sLstA = deque()
self._rIntA = 1
self._rIntB = 0
for self._rStrA in self._rStrB:
self._rBoolA = False
if self._rStrA == '0':
self._rStrD = self._rStrA
self._rStrA = int(self._rStrC)+self._rIntA
if self._rStrA > 9:
self._rStrA = math.ceil((int(self._rStrB) * int(self._rStrC)) / self._rIntA)
if self._rStrA > 11: self._rStrA = self._rStrA - 10
self._rStrA = str(self._rStrA)
self._rStrA = self._rStrA[0]
else: self._rStrA = str(self._rStrA)
if self._rStrA == '9':
self._rBoolA = True
self._rIntB += 1
if self._rBoolA:
if self._rIntB >= 3: self._sLstA.append(3 * int(self._rStrA) / self._rIntA)
else: self._sLstA.append(6 * int(self._rStrA) / self._rIntA)
else:
if self._rStrA != '9': self._sLstA.append(6 * int(self._rStrA) / self._rIntA)
else: self._sLstA.append(3 * int(self._rStrA) / self._rIntA)
self._rStrC = self._rStrA
self._rIntA += 1
# Check all n-elements in _rLstA are proper 4:1 pre-format fractions.
# This should pair up with collatz S and algorithm above, with a .25
# being a very elusive find in _rLstA because of a _rIntC placeholds.
# Menorah base is always a 4:1 balance in 3:1 rotatable progressions.
# Like your hands, 4 after same pair is loop(thumb) into pair center.
# If you counts 9 to either RtoL or LtoR by your digit fingers only;
# both loops(thumbs) are always even 1:1 separate from each 4 L&R --
# though inseparate if re-start with a outer loop count on one thumb.
self._rIntB = len(self._sLstA)
for self._rIntA in range(self._rIntB):
self._rStrA = str(self._sLstA[self._rIntA])
if self._rStrA.find('.0') > -1 or self._rStrA.find('.25') > -1 or self._rStrA.find('.5') > -1 or self._rStrA.find('.75') > -1: self._rBoolA = True
else:
self._rBoolA = False
break
if self._rBoolA: print(f'M9-calc status: meet')
else:
# Exit sequences, would not go sound after this.
pass
if len(self._sPlndrmSeq) > 0:
self.menorahInnerPalindromesExtract()
#TODO
else:
#TODO
print('(no palindromes found yet)')
#<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>
def menorahInnerPalindromesExtract(self):
# slots attrs in strict refrence: none so far
self._rIntA = self._sIntB - self._sIntA - 1
self._rIntB = self._sIntB - 1
self._rLstA = deque()
self._rLstB = deque()
self._rIntC = 0
while self._rIntA > 0:
self._rLstA.append(self._sCltzSeq[self._rIntB])
self._rIntD = len(self._rLstA) - 1
if self._rIntC >= self._rIntB:
self._rStrA = str(self._sCltzSeq[self._rIntC])
self._rIntE = len(self._rStrA)
if self._rStrA == self._rStrA[::-1]:
if self._rIntA > self._sIntA + 1: self._rLstB.append(math.ceil((self._rIntA + self._rIntE + self._sCltzSeq[self._rIntC]) / 2))
else:
if self._rIntE >= 3: self._rLstB.append(self._rIntA + self._rIntE + self._sCltzSeq[self._rIntC] + 9)
else: self._rLstB.append(self._rIntA + self._rIntE + self._sCltzSeq[self._rIntC] - 9)
self._rIntF = len(self._rLstB) - 1
if self._rLstB[self._rIntF] < 0: self._rLstB[self._rIntF] = 11 + self._rIntE
else:
self._rLstB.append(math.ceil(((self._rIntE * self._rIntA) + self._rIntC + self._rIntC) / 2))
self._rIntF = len(self._rLstB) - 1
if self._rLstB[self._rIntF] < self._rLstA[self._rIntD]: self._rLstB[self._rIntF] += 3
elif self._rLstB[self._rIntF] > self._rLstA[self._rIntD]: self._rLstB[self._rIntF] -= 3
else: self._rLstB.append(self._sCltzSeq[self._rIntC])
self._rIntB -= 1
self._rIntC += 1
self._rIntA -= 1
print(f'RtoL: {self._rLstB}')
# TODO: check if this list is a super reorder having number 121 repeated
print(f'LtoR: {self._rLstA}')
# TODO: check if this list sets is closer to palindrome than aboves, if
# is then a divisional parsing needs to be on at above function until 1
#<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>
def setNewSeqSet(self, x, rs, re):
print(f'___|> Getting new start numbers, initial total set request is ({x})')
self._sSeqSet = set()
for self._sIntA in range(x): self._sSeqSet.add(random.randint(rs, re))
self._sSeqSet = list(self._sSeqSet)
#<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>▪︎.<|>.▪︎<|>
def test():
cls = TT777_SPICE()
cls.setNewSeqSet(100, 9, 999)
setLen = len(cls._sSeqSet)
for i in range(setLen):
cls.collatz()
cls.findSpice()
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment