dimanche 3 juillet 2011

Euler #112

#!/usr/bin/python
n = 1
b = 0
def is_bouncy(n):
if len(str(n)) <= 2:
return False
l = map(int, str(n))
inc = all(x <= y for x, y in zip(l, l[1:]))
dec = all(x >= y for x, y in zip(l, l[1:]))
return (not inc) and (not dec)
while True:
if is_bouncy(n):
b += 1
if b*100 == 99*n:
print n
break
n += 1
view raw 112.py hosted with ❤ by GitHub

Aucun commentaire:

Enregistrer un commentaire