Created
July 2, 2018 04:43
-
-
Save douglascodes/a9c667bd47d71f6c056ddc7bba123dcf to your computer and use it in GitHub Desktop.
Recamán sequence simple.
This file contains 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
import sys | |
from collections import Counter | |
def main(): | |
next_location = 0 | |
history = Counter() | |
for i in range(1, 100): | |
print(next_location) | |
next_location = racaman(next_location, i, history) | |
return | |
def racaman(location: int, iteration: int, history: dict): | |
history.update([location]) | |
if iteration >= location: | |
return location + iteration | |
if history[location - iteration] == 0: | |
return location - iteration | |
return location + iteration | |
if __name__ == '__main__': | |
main() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment