Skip to content

Commit 4c6c40e

Browse files
Jakub KadlubiecJakub Kadlubiec
authored andcommitted
Add problem 112
0 parents  commit 4c6c40e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

problem112/solution.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import itertools
2+
3+
def isBouncy(number):
4+
def getDigits(n):
5+
while n:
6+
yield n % 10
7+
n //= 10
8+
9+
isDecreasing, isIncreasing = True, True
10+
11+
digits = getDigits(number)
12+
previousDigit = next(digits)
13+
14+
for currentDigit in digits:
15+
if currentDigit > previousDigit:
16+
isDecreasing = False
17+
elif currentDigit < previousDigit:
18+
isIncreasing = False
19+
20+
if isDecreasing is False and isIncreasing is False:
21+
return True
22+
23+
previousDigit = currentDigit
24+
25+
return False
26+
27+
def calculateResult():
28+
totalBouncy = 0
29+
for number in itertools.count(1):
30+
if isBouncy(number):
31+
totalBouncy += 1
32+
33+
if totalBouncy * 100 == number * 99:
34+
return number
35+
36+
result = calculateResult()
37+
38+
print("Result: {0}".format(result))

0 commit comments

Comments
 (0)