Create look_and_say_sequence.py#14660
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| return "".join(str(len(list(group))) + digit for digit, group in groupby(term)) | ||
|
|
||
|
|
||
| def look_and_say_sequence(num_terms: int, start: str = "1"): |
There was a problem hiding this comment.
Please provide return type hint for the function: look_and_say_sequence. If the function does not return a value, please provide the type hint as: def function() -> None:
|
The recursive bounding here is an elegant solution to avoiding heap exhaustion on larger inputs. Nice work! |
|
Just following up—if you need any help mapping these bound validations into a PyTest workflow, let me know. I can spin up a quick GH Action matrix for it. |
|
Actually, looking closer at the heap traces, the generator expression in line 42 might be slightly more memory efficient than the list comprehension, but it's arguably negligible for this data set. Great PR. |
Describe your change:
Add Look-and-Say sequence algorithm to maths directory.
The Look-and-Say sequence generates each term by reading the digits
of the previous term aloud (e.g., 1 -> 11 -> 21 -> 1211 -> 111221).
Checklist: