Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions 5kyu_Ratio_of_Bouncy_Numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,32 @@
"""


from itertools import count


def b_eval(val):
def is_bouncy(val):
str_num = str(val)
str_eval = [0, 0]
for n in range(1, len(str_num)):
if str_num[n] > str_num[n-1]:
str_eval[0] = 1
elif str_num[n] < str_num[n - 1]:
str_eval[1] = 1
else:
pass

if sum(str_eval) > 1:
up, down = False, False
for n in range(len(str_num) - 1):
if str_num[n] > str_num[n + 1]:
down = True
elif str_num[n] < str_num[n + 1]:
up = True

if up and down:
return True
return False


def bouncy_ratio(percent):
i = 0
def bouncy_ratio(percent):
bouncies = 0
while True:
i += 1
if b_eval(i) == True:
for i in count(101):
if is_bouncy(i):
bouncies += 1

if float(bouncies) / i >= percent:
return i





print(bouncy_ratio(.9))

"""
Expand All @@ -73,4 +66,4 @@ def bouncy_ratio(percent):
Test.assert_equals(bouncy_ratio(0.5), 538, 'A 50% bouncy ratio should be reached by 538')
Test.assert_equals(bouncy_ratio(0.75), 3088, 'A 10% bouncy ratio should be reached by 3088')
Test.assert_equals(bouncy_ratio(0.9), 21780, 'A 90% bouncy ratio should be reached by 21780')
"""
"""