Look-and-Say Sequence

An interesting nonmathematical sequence which yet has interesting mathematical properties is the Look-and-say sequence.
As every good sequence it starts with a 1. From there you get each next entry by looking at the previous and saying it. The next entry will thus be “one 1” or 11. From there “two 1” or 21, then “one 2; one 1” or 1211, “one 1; one 2; two 1” or 111221 and so on.

Generating the sequence

Generating the Look-and-say sequence
The mathematical property although does not lie in the entry’s value, but rather in its length.

Calculating the length of each entry

Getting the Look-and-say sequence's lengthThe interesting thing about the length is, that it approximately grows by λ each time. \big( \lambda = 1.303577269034\dots \big)
This constant λ can be calculated by getting the real root of a degree 71 polynomial (see Nathaniel Johnston’s post for further information) or be approximated by dividing entrys. \big( \lambda = \frac{\text{entry}_{n+1}}{\text{entry}_{n}} \text{ for } n \rightarrow \infty \big)

Approximating λ

Approximating lambda

# Python 2.7.7 Code
# Jonathan Frech 25th of February, 2016
#         edited 26th of February, 2016
#         edited 28th of February, 2016
#         edited  4th of March   , 2016

# set the program's mode
MODE = ["sequence", "length", "lambda"][2]

# advance the sequence
def advance(seq):
	# special case
	if seq == "":
		return "1"

	# result
	res = ""

	# init
	c = seq[0]
	a = 1
	seq = seq[1:len(seq)]
	# loop (look at the sequence and 'say' it)
	for s in seq:
		if s == c:
			a += 1
			res += str(a) + c
			c = s
			a = 1

	# return
	return res + str(a) + c

# generate the sequence
if MODE == "sequence":
	seq = ""
	while True:
		seq = advance(seq)
		print seq

# generate the sequence and get each entry's length
elif MODE == "length":
	seq = ""
	while True:
		seq = advance(seq)
		print len(seq)

# approximate lambda
elif MODE == "lambda":
	seq = ""
	while True:
		nseq = advance(seq)
		if len(seq) > 0:
			print "lambda approx. " + str(1. * len(nseq) / len(seq))
		seq = nseq

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.