-
Notifications
You must be signed in to change notification settings - Fork 0
/
p112.py
44 lines (36 loc) · 872 Bytes
/
p112.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python2.7
from utils import factorial
def comb(n,k):
return factorial(n)/(factorial(k)*factorial(n-k))
def cyphers(num):
return map(int, str(num))
def isincreasing(num):
c = cyphers(num)
for p in xrange(len(c)-1):
if c[p] < c[p+1]:
return False
return True
def isdecreasing(num):
c = cyphers(num)
for p in xrange(len(c)-1):
if c[p] > c[p+1]:
return False
return True
def isbouncy(num):
return not isincreasing(num) and not isdecreasing(num)
if __name__ == "__main__":
nums = range(1,1001)
k = 0
ratio = 0
n = 1
inc = 0
dec = 0
for n in nums:
if isincreasing(n):
inc += 1
if isdecreasing(n):
dec += 1
if isbouncy(n):
k += 1
print n, inc, dec, k
print comb(10,2), comb(10,3)