In [42]:
initial_state = '01111010110010011'
disk_length = 272
In [40]:
def dragon_iterator(initial_state):
a = [int(i) for i in list(initial_state)]
while len(a) > 0:
b = [1 - int(i) for i in reversed(a)]
a = a + [0] + b
yield(''.join([str(i) for i in a]))
def dragon_checksum(intial_state, disk_length):
data = initial_state
gen = dragon_iterator(initial_state)
while len(data) < disk_length:
data = next(gen)
data = data[:disk_length]
while len(data) % 2 == 0:
pair_list = [data[2*i:2*(i+1)] for i in range(len(data)//2)]
data = ''.join([str(2-len(set(item))) for item in pair_list])
return data
In [43]:
%%time
s = dragon_checksum(initial_state, disk_length)
print(s)
print(len(s))
In [44]:
%%time
new_disk_length = 35651584
t = dragon_checksum(initial_state, new_disk_length)
print(t)
print(len(t))