Created
August 14, 2017 11:45
-
-
Save takapiko/500d97d326a7d5ae7a1d2d70379846b5 to your computer and use it in GitHub Desktop.
KolakoskiSequenceを生成するプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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