Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Not pretty, but readable solution in Clear category for Beat The Previous by BootzenKatzen
def beat_previous(digits: str) -> list[int]:
nums = list(map(int, list(digits)))
result = []
current_s = ''
current_n = None
while nums:
if current_n == None:
current_n = nums.pop(0)
if not result or current_n > result[-1]:
result.append(current_n)
current_n = None
elif current_n == 0:
current_n = None
elif current_n <= result[-1] and nums != []:
current_s = str(current_n)
current_s += str(nums.pop(0))
current_n = int(current_s)
else:
break
if current_n != None and current_n > result[-1]:
result.append(current_n)
return result
beat_previous("77777777777777777777777")
print("Example:")
print(beat_previous("123"))
print(beat_previous("77777777777777777777777"))
# These "asserts" are used for self-checking
assert beat_previous("600005") == [6]
assert beat_previous("6000050") == [6, 50]
assert beat_previous("045349") == [0, 4, 5, 34]
assert beat_previous("77777777777777777777777") == [7, 77, 777, 7777, 77777, 777777]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 14, 2023