Euler Problem 112

I’m on a roll! Just banging them out. Must be just a series of easy ones. Just iterate over a range, checking each for increasing and decreasing numbers, then increment a counter.

#Euler112
import psyco
psyco.full()

class Problem:
    def isInc (self, num):
        counter = 0
        for c in str(num):
            if int(c) >= counter:
                counter = int(c)
            else:
                return False
        return True
    def isDec (self, num):
        counter = 9
        for c in str(num):
            if int(c) <= counter:
                counter = int(c)
            else:
                return False
        return True
    def Solution(self):
        bouncy = 0
        for i in range (1, 2000000):
            if self.isInc(i) == False and self.isDec(i) == False:
                bouncy += 1
            if float(bouncy)/i == .99:
                break
        print "Answer=", i
if __name__ == '__main__':
    P = Problem()
    P.Solution()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s