62 lines
1.4 KiB
Python
62 lines
1.4 KiB
Python
|
import pandas as pd
|
||
|
import time
|
||
|
|
||
|
def main():
|
||
|
"""
|
||
|
Print out a sequence following the see-it sequence
|
||
|
"""
|
||
|
|
||
|
upper_bound = 100
|
||
|
seed = "1"
|
||
|
file_location = "output.csv"
|
||
|
|
||
|
df = pd.DataFrame(columns=["Iteration", "Length", "Value"])
|
||
|
|
||
|
val = seed
|
||
|
|
||
|
for i in range(0,upper_bound):
|
||
|
#print(f"Iteration : {i}")
|
||
|
#print(f"Length : {len(val)}")
|
||
|
#print(val)
|
||
|
df.loc[len(df)] = [i, len(val), val]
|
||
|
start_time = time.time()
|
||
|
val = next_step(val)
|
||
|
elasped_time = time.time() - start_time
|
||
|
print(f"Iteration : {i} of {upper_bound} (took {elasped_time:.4f} seconds)")
|
||
|
df.to_csv(file_location, index=False)
|
||
|
print("Progress saved to file")
|
||
|
print("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
|
||
|
|
||
|
print("Result logged to {file_location.csv}")
|
||
|
|
||
|
|
||
|
def next_step(sequence: str) -> str:
|
||
|
last_char = None
|
||
|
last_char_count = 0
|
||
|
|
||
|
ret = ""
|
||
|
|
||
|
for char in sequence:
|
||
|
if last_char == None:
|
||
|
last_char = char
|
||
|
last_char_count = 1
|
||
|
elif char == last_char:
|
||
|
last_char_count += 1
|
||
|
else:
|
||
|
ret += str(last_char_count)
|
||
|
ret += str(last_char)
|
||
|
last_char_count = 1
|
||
|
last_char = char
|
||
|
|
||
|
if ret != None:
|
||
|
ret += str(last_char_count)
|
||
|
ret += str(last_char)
|
||
|
|
||
|
|
||
|
return ret
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|