- #36
pbuk
Science Advisor
Homework Helper
Gold Member
- 4,800
- 3,075
I think if you are going to make any progress in this subject you should learn to do these things for yourself. If you don't like the look of @jbriggs444's Perl code, try it in Python: you can run it for yourself without installing anything at https://replit.com/@pbuk/StingyInfiniteNlp#main.py, and if you sign up for a repl.it account you can even try some edits.Adel Makram said:Is it possible to run your program to find the minimum length of symbols in the same generation that repeats itself?
Python:
# See https://www.physicsforums.com/threads/arithmetic-representation-of-symbols-according-to-certain-rules.1016467/
replacements = {
'A': 'B',
'B': 'C',
'C': 'DE',
'D': 'FC',
'F': 'GA',
'G': 'C',
'E': 'HI',
'H': 'J',
'I': 'D',
'J': 'D',
}
def transform(input):
''' Transform the input according to the rules '''
output = ''
for char in input:
output += replacements[char]
return output
truncateAt = 10
# Set the initial conditions.
current = 'A'
history = []
# This concise loop does all the work!
while not current in reversed(history):
history.append(current)
current = transform(current)[:truncateAt]
# Report the results.
cycle = len(history) - history.index(current)
count = len(history)
history.append(current)
print('Cycle length', cycle, 'after', count, 'iterations')
if truncateAt <= 100:
for index, item in enumerate(history):
if index == count - cycle or index == count:
print(index, item, '<<<')
else:
print(index, item)