Skip to content

Instantly share code, notes, and snippets.

@douglascodes
Created July 2, 2018 04:43
Show Gist options
  • Save douglascodes/a9c667bd47d71f6c056ddc7bba123dcf to your computer and use it in GitHub Desktop.
Save douglascodes/a9c667bd47d71f6c056ddc7bba123dcf to your computer and use it in GitHub Desktop.
Recamán sequence simple.
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