class PyReversible(object):
__slots__ = ['max','numReversible']
def __init__(self, max):
self.max = max
self.numReversible = self.countReversible()
def countReversible(self):
return len([i for i in xrange(11,self.max+1) if self.reversible(i)])
def allOdd(self,n):
for ch in str(n):
if int(ch) % 2 != 1:
return False
return True
def reverse(self,n):
return n + int(str(n)[::-1])
def reversible(self,n):
return self.allOdd(self.reverse(n))
Wednesday, May 20, 2009
JavaOne Talk: Python Reversible Numbers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment