Created
August 26, 2021 00:27
-
-
Save jeanmw/38361dfb70b056961744e3d1765da00c to your computer and use it in GitHub Desktop.
Infinite python number generator
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
| # Write a one-line Python generator expression that provides an infinite stream | |
| #of unique integers that are evenly divided by any of the ascii values for | |
| #the characters in “jean”. | |
| # There are likely many ways to do this correctly. | |
| # I have made some assumptions - that sequential ordering is alright, | |
| # and that although python3 technically does not have a integer limit | |
| # we want to have some kind of reasonable size limit based on max pointer size | |
| # If we were in python 2 we would need to limit the range to sys.maxint | |
| # I have explicitly imported things here as well just for clarity although | |
| # the instructions did not require it. | |
| import sys | |
| from itertools import count | |
| from random import randrange | |
| word = "jean" | |
| infinite_close_unique_number_generator = (num for num in range(0, sys.maxsize**10) if len([True for ascii_val in [ord(letter) for letter in "jean"] if num % ascii_val == 0]) > 0) | |
| # Calling the generator | |
| next(infinite_close_unique_number_generator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment