Posted by free-zombie on Wed 22 Oct 23:01
report abuse | download | new post
- def digits_unique(n):
- ns = str(n)
- for c in ns:
- if ns.count(c) > 1:
- return False
- return True
- class UniqDigitsFinder:
- def __init__(self):
- self.maxjump = 0
- self.count = 0
- def with_uniq_digits(self, start, end):
- jump = 0
- for i in xrange(start, end+1):
- if digits_unique(i):
- self.count += 1
- jump = 1
- yield i
- else:
- jump += 1
- if jump > self.maxjump:
- self.maxjump = jump
- def uniqdigitstats(start, end):
- uc = UniqDigitsFinder()
- for x in uc.with_uniq_digits(start, end):
- pass
- print "Number of values: %d" % uc.count
- print "Longest jump: %d" % uc.maxjump
- if __name__ == '__main__':
- import sys
- uniqdigitstats(1, int(sys.argv[1]))
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.