Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Peter's Files
Views: 3893
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu1804
Kernel: Python 3 (system-wide)

Counting Pattern

Define C(n)\mathcal{C}(n) as the recursively defined sequence of integers whose iith term is the 'verbal summary' of the digits in the previous term and whose first term is nn.

Example:

If 12321232 is a term, the next term is 112213112213 because 12321232 contains one 11, two 22s, and one 33.

import numpy as np from numba import njit import matplotlib.pyplot as plt
@njit def split(it:str): return [char for char in it]
def nextNum(initNum:str): splitUp = split(initNum) seq = '' for occurance in range(max([int(i) for i in splitUp])+1): howMany = splitUp.count(str(occurance)) if howMany != 0: seq += str(howMany) + str(occurance) return seq # return ''.join(str(splitUp.count(str(occurance))) + str(occurance) if splitUp.count(str(occurance)) != 0 else '' for occurance in range(max([int(i) for i in splitUp])+1))
def C(initialNumber:str): tot = [initialNumber] prev = initialNumber while True: nextNumber = nextNum(prev) if nextNumber == prev: break tot += [nextNumber] prev = nextNum(prev) return tot, len(tot)

test a bunch

data = np.zeros(50) for a in range(1,50): data[a] = C(str(a))[1]
C('39')
(['39', '1319', '211319', '31121319', '41122319', '3122131419', '4122231419', '3132132419', '3122331419'], 9)
data[40]
0.0
fig, ax = plt.subplots(figsize=(7,7)) ax.set_aspect('equal') ax.autoscale() x=np.linspace(-1,1,500) y_1 = np.sqrt(1-x**2) y_2 = -np.sqrt(1-x**2) ax.plot(x,y_1,'k'); ax.plot(x,y_2,'k'); ax.plot(*generate(0,angle,bounces));