Skip to content

Instantly share code, notes, and snippets.

@mrklein
Created May 18, 2012 17:03
Show Gist options
  • Save mrklein/2726430 to your computer and use it in GitHub Desktop.
Save mrklein/2726430 to your computer and use it in GitHub Desktop.
Project 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment