File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments