Skip to content

Instantly share code, notes, and snippets.

@607011
Created April 2, 2025 06:10
Show Gist options
  • Save 607011/d2cb7fc6df30c926108e1ad36f650ac7 to your computer and use it in GitHub Desktop.
Save 607011/d2cb7fc6df30c926108e1ad36f650ac7 to your computer and use it in GitHub Desktop.
Generate "look-and-say" integer sequence
#!/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