Created
April 2, 2025 06:10
-
-
Save 607011/d2cb7fc6df30c926108e1ad36f650ac7 to your computer and use it in GitHub Desktop.
Generate "look-and-say" integer sequence
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
https://oeis.org/A005150 | |
""" | |
s = "1" | |
seq = [s] | |
for i in range(10): | |
result = "" | |
while len(s) > 0: | |
d = s[0] | |
n = 1 | |
for c in s[1:]: | |
if c != d: | |
break | |
n += 1 | |
result += f"{n}{d}" | |
s = s[n:] | |
s = result | |
seq.append(s) | |
print(", ".join(seq)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment