Clap sequence

 The clap sequence is a sequence that generates a list using the previous list's numbers. It starts with [1], and then the frequency of the same numbers in a row is added, followed by the actual number itself. Therefore, the next sequence would be [1, 1], as there is one 1, then it would be [2, 1], as there are two 1s, then [1, 2, 1, 1], as there is one 2 and one 1.

array = [1]
for sentinel in range(0, 10):
count = 1
new_array = []
for x in range(0, len(array)):
number = array[x]
try:
if array[x] == array[x+1]:
count += 1
else:
new_array.append(count)
new_array.append(number)
count = 1
except IndexError as e:
new_array.append(count)
new_array.append(number)
array = new_array
print(array)
This is the outcome:
[1, 1]
[2, 1]
[1, 2, 1, 1]
[1, 1, 1, 2, 2, 1]
[3, 1, 2, 2, 1, 1]
[1, 3, 1, 1, 2, 2, 2, 1]
[1, 1, 1, 3, 2, 1, 3, 2, 1, 1]
[3, 1, 1, 3, 1, 2, 1, 1, 1, 3, 1, 2, 2, 1]
[1, 3, 2, 1, 1, 3, 1, 1, 1, 2, 3, 1, 1, 3, 1, 1, 2, 2, 1, 1]
[1, 1, 1, 3, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 1, 3, 2, 1, 1, 3, 2, 1, 2, 2, 2, 1]

Comments