0 Replies - 2002 Views - Last Post: 21 September 2012 - 02:34 PM

#1 atraub   User is offline

  • Pythoneer
  • member icon

Reputation: 833
  • View blog
  • Posts: 2,257
  • Joined: 23-December 08

RATS Generator

Posted 21 September 2012 - 02:34 PM

Description: It's a standard generator. You can create an instance of it with: x = rats_generator(value) and then you can get values with: next(x)A sequence produced by the instructions "reverse, add to the original, then sort the digits." For example, after 668, the next iteration is given by so the next term is 1345. Applied to 1, the sequence gives 1, 2, 4, 8, 16, 77, 145, 668, 1345, 6677, 13444, 55778, 133345, 666677, 1333444, 5567777, 12333445, 66666677, 133333444, 556667777, 1233334444, 5566667777, 12333334444, 55666667777, 123333334444, 556666667777, 1233333334444, ...
__author__ = "atraub"
__date__= "9/21/2012"

def rats_generator(seed):
    """A generator to create RATS numbers"""
    while True:
        seed = int("".join(sorted(str(seed + int(str(seed)[::-1])))))
        yield seed



Is This A Good Question/Topic? 0
  • +

Page 1 of 1