Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brute force solution in Clear category for Staircase by igharok
from itertools import combinations
from contextlib import suppress
def beat_previous(digits: str) -> list[int]:
list_inc = []
str_next = ''
for chr_i in digits:
str_next += chr_i
if (len(list_inc) == 0) or (int(str_next) > int(list_inc[-1])):
list_inc.append(int(str_next))
str_next = ''
return list_inc
def staircase(digits: str) -> int:
return max(len(beat_previous(s)) for n in range(1, len(digits)) for s in combinations(digits, n))
print("Example:")
print(staircase("31415926"))
# These "asserts" are used for self-checking
assert staircase("100123") == 4
assert staircase("503715") == 4
assert staircase("0425494220946") == 6
assert staircase("04414952075836") == 7
assert staircase("1234567891011213") == 12
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 10, 2025
Comments: