Skip to content

Instantly share code, notes, and snippets.

@takapiko
Created August 14, 2017 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takapiko/500d97d326a7d5ae7a1d2d70379846b5 to your computer and use it in GitHub Desktop.
Save takapiko/500d97d326a7d5ae7a1d2d70379846b5 to your computer and use it in GitHub Desktop.
KolakoskiSequenceを生成するプログラム
# coding: UTF-8
def kolakoski_transformation(seq):
l = []
temp = seq[0]
count = 0
for n in seq:
if(n == temp):
count+=1
else:
l.append(count)
temp = n
count =1
l.append(count)
return l
def kolakoski_sequence(integers,length):
l = []
index = 0
while len(l)<length:
for n in integers:
if(len(l)<=index):
l.extend([n]*n)
index+=1
else:
l.extend([n]*l[index])
index+=1
return l[:length]
seq =kolakoski_sequence([1,2],100)
print(seq)
print(kolakoski_transformation(seq))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment