-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path112.py
More file actions
46 lines (32 loc) · 953 Bytes
/
112.py
File metadata and controls
46 lines (32 loc) · 953 Bytes
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
45
46
"""Project Euler Problem 112: https://projecteuler.net/problem=112"""
# Counts monotone-digit numbers to find when the proportion of bouncy numbers reaches 99%.
from math import gcd
from fractions import Fraction
#!/usr/bin/env python3
# farey_stream.py
# Stream all reduced proper fractions 0<n<d<=N in ascending order.
from math import floor
def solve(N):
"""Find the least integer for which the proportion of bouncy numbers reaches 99%."""
i = 1
cnt = 0
while True:
j = i
up = True
down = True
prev_r = -1
while j > 0:
r = j % 10
j = j // 10
if prev_r != -1:
if r < prev_r:
down = False
elif r > prev_r:
up = False
prev_r = r
if not up and not down:
cnt += 1
if cnt / i == 0.99:
return i
i += 1
print(solve(10))